On Feb 15, 2011, at 5:07 AM, Robert Pankowecki <[email protected]> wrote:
> o = Organization.first > o.people.includes(:addresses).each do |p| > puts p > puts p.addresses > end # 2 queries are executed, normal and for eager loading addresses > > but > > o.people.loaded? => false > > Is that a bug or by-design behavior that o.people.includes(:address) > won't store the fetched records in o.people association ? > > Robert Pankowecki That's by design. When you chain a scope off an associationproxy, it's basically syntactic sugar for constructing your query the long way, by doing Person.where(:organization_id => o.id)[...] In the case you gave, above, the people association never needed to load as the new scope was created, and to store the result of the query you eventually executed in that association would be the wrong thing to do -- it may have had additional conditions limiting the results that would not fully load the association. Inside your block, though, p.addresses.loaded? will be true, which is what you asked for. Hope this helps! -- 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 [email protected]. 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.
