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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
vinhboy (Guest)
on 2009-01-23 18:02
(Received via mailing list)

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


( 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.