aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-04-19 10:39:12 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-04-19 10:39:12 +0000
commit4e2f7bec6fc156c24acfb1632fecee38c14f721d (patch)
treee87f4cafd1782a7e25e4145006b65a89e8dca98a /activerecord/lib
parent865874ab6a8be80d896604ba4106e14b57ebfdc5 (diff)
downloadrails-4e2f7bec6fc156c24acfb1632fecee38c14f721d.tar.gz
rails-4e2f7bec6fc156c24acfb1632fecee38c14f721d.tar.bz2
rails-4e2f7bec6fc156c24acfb1632fecee38c14f721d.zip
Added documentation about :limit not working with eager loading
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1224 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 273c210d63..59eb437c45 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -121,7 +121,7 @@ module ActiveRecord
#
# Consider the following loop using the class above:
#
- # for post in Post.find(:all, :limit => 100)
+ # for post in Post.find(:all)
# puts "Post: " + post.title
# puts "Written by: " + post.author.name
# puts "Last comment on: " + post.comments.first.created_on
@@ -129,20 +129,23 @@ module ActiveRecord
#
# To iterate over these one hundred posts, we'll generate 201 database queries. Let's first just optimize it for retrieving the author:
#
- # for post in Post.find(:all, :limit => 100, :include => :author)
+ # for post in Post.find(:all, :include => :author)
#
# This references the name of the belongs_to association that also used the :author symbol, so the find will now weave in a join something
# like this: LEFT OUTER JOIN authors ON authors.id = posts.author_id. Doing so will cut down the number of queries from 201 to 101.
#
# We can improve upon the situation further by referencing both associations in the finder with:
#
- # for post in Post.find(:all, :limit => 100, :include => [ :author, :comments ])
+ # for post in Post.find(:all, :include => [ :author, :comments ])
#
# That'll add another join along the lines of: LEFT OUTER JOIN comments ON comments.post_id = posts.id. And we'll be down to 1 query.
# But that shouldn't fool you to think that you can pull out huge amounts of data with no performance penalty just because you've reduced
# the number of queries. The database still needs to send all the data to Active Record and it still needs to be processed. So its no
# catch-all for performance problems, but its a great way to cut down on the number of queries in a situation as the one described above.
#
+ # Please note that because eager loading is fetching both models and associations in the same grab, it doesn't make sense to use the
+ # :limit property and it will be ignored if attempted.
+ #
# == Modules
#
# By default, associations will look for objects within the current module scope. Consider: