Skip to content

Instantly share code, notes, and snippets.

@naudo
Created August 13, 2012 00:05
Show Gist options
  • Save naudo/3335597 to your computer and use it in GitHub Desktop.
Save naudo/3335597 to your computer and use it in GitHub Desktop.
A simple view to show how easy writing n + 1 queries really is.
<% User.all.each do |user| %>
<p> <%= user.name %> </p>
<ul>
<% user.pets.each do |pet| %>
<li> <%= pet.name %> </li>
<% end %>
</ul>
<% end %>
@statianzo
Copy link

Not to mention, User.all is unwise. While it doesn't ever seem slow when you're in development, it's certainly a ticking time bomb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment