Sorry, but I thought it is about Rails implementation details, has_many implementation details.
On Aug 7, 3:01 pm, Manfred Stienstra <[EMAIL PROTECTED]> wrote: > This mailing list is meant for discussion about implementation > details of Rails only. You can post support requests to Rails Talk > [1] or #rubyonrails on freenode. > > [1]http://groups.google.com/group/rubyonrails-talk > > On Aug 7, 2007, at 2:44, paccator wrote: > > > > > Why has_many doesn't set target for objects in its collection? > > > E.g. when > > > class Author < ActiveRecord; has_many :posts; end > > class Post < ActiveRecord; belongs_to :author; end > > > then > > > some_author.posts.each {|p| puts p.author.name} > > > will require additional queries to fetch author for each post. > > That said, some_author.posts.find(:all, :include => :author).each { | > p| puts p.author.name } will do a JOIN for you. Although that > shouldn't be necessary if you put some_author in an instance variable > and read it from there. > > Manfred That said, :include is not a solution, cause it also unnecessarily makes bigger query just to fetch object which I already have in memory. Instant variable is not enough. My example was intentionally simple just to show what I mean. Imagine that I have few authors somewhere, and I collect their posts, and this posts list is accessed from outside. Also I was more hoping to see opinion about suggested extension to has_many. paccator --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---