In the documentation for eager loading it is stated that:
If you eager load an association with a specified :limit option, it will be ignored, returning all the associated objects:
class Picture < ActiveRecord::Base
has_many :most_recent_comments, :class_name => 'Comment',
:order => 'id DESC', :limit => 10
end
Picture.find(:first, :include => :most_recent_comments).most_recent_comments # => returns all associated comments.
If this is the case then what is the best way to achieve the "limit" on the loading?
Let's say we're eager loading the last 10 blog posts onto the front page of a blog, we clearly don't want them all so should the limit and ordering of the post collection be specified?
Further to that, can one specify the same conditions on elements that are deep loaded - for instance only show the first three comments on each blog post?
Blog.find(:blog_id, :include => {:posts => :comments } )