Forum: Ruby on Rails Eager loading issue

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.
D9d1b31a337f46ac5e4dd56b55404f58?d=identicon&s=25 Dylan Markow (Guest)
on 2006-02-10 05: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.
3ccecc71b9fb0a3d7f00a0bef6f0a63a?d=identicon&s=25 Kent Sibilev (Guest)
on 2006-02-10 05:34
(Received via mailing list)
In this case you should fall back to using find_by_sql method.

This topic is locked and can not be replied to.