Forum: Ruby on Rails eager loading in the Model versus in find

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
45afc5b02255db47aecea5504be609cf?d=identicon&s=25 vinhboy (Guest)
on 2009-01-23 17:02
(Received via mailing list)
Hi,

Can you someone help me understand this.

When I am eager loading something in the Model, like this:

-----------------
Class Customer < ActiveRecord::Base

  has_many :orders, :include => :line_items

end
-----------------

( assume orders and line_items belongs_to customer, and order has_many
line_items )
versus in the controller like this:

@customers = Customer.find(:all, :include => [:orders => :line_items])

I get different results.
Declaring the eager loading in the Model does not work.
But when I do it through the find, it works, I can see the data being
fetched in the SQL and I can see it in the instance variable.

Thank You.
This topic is locked and can not be replied to.