Forum: Ruby on Rails Eager loading issue

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.
Dylan M. (Guest)
on 2006-02-10 06:14
(Received via mailing list)
I have three tables, Invoices, Projects, and Managers.

Each manager has many projects. Each project has many invoices.

When displaying a list of the invoices, I am using:

Invoice.find(:all, :include => [:project])

Since the list shows information from the project table. (For
example, a table showing Invoice Date, Project Name). However, I'd
also like to show the manager name. Theoretically, i'd like to be
able do an eager loading of both :project, and :manager. Right now,
my list generates an individual SQL query for each invoice to display
the manager name. Trying to do :include => [:project, :manager]
obviously doesn't work, as the manager_id is linked into the Projects
table, not Invoices.
Kent S. (Guest)
on 2006-02-10 06:34
(Received via mailing list)
In this case you should fall back to using find_by_sql method.

Kent.
This topic is locked and can not be replied to.