Forum: Rails-core (closed, excessive spam) Eager loading doesn't respect :limit option of the macro association

Posted by Luca Guidi (Guest)
on 2008-06-28 11:49
(Received via mailing list)
Hi all,
I found a strange behaviour in eager loading:

class Category < ActiveRecord::Base
   has_and_belongs_to_many :movies
   has_and_belongs_to_many :most_recent_movies, :class_name => 'Movie',
:order => 'created_at DESC', :limit => 10
end

class Movie < ActiveRecord::Base
   has_and_belongs_to_many :categories
end

Category.find(1).most_recent_movies # => returns 10 movies

Category.find(1, :include => :most_recent_movies).most_recent_movies #
=> returns all the associated movies

I fixed it, you can find the patch at:
http://rails.lighthouseapp.com/projects/8994-ruby-...


Best,
Luca
--
blog: www.lucaguidi.com
Pro-Netics: www.pro-netics.com
Sourcesense - making sense of Open Source: www.sourcesense.com
This topic is locked and can not be replied to.