Created
August 13, 2012 00:05
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% User.all.each do |user| %> | |
<p> <%= user.name %> </p> | |
<ul> | |
<% user.pets.each do |pet| %> | |
<li> <%= pet.name %> </li> | |
<% end %> | |
</ul> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.