Best way to eager load accross multiple relationships?


#1

Let’s say I have Departments, which have many Persons , which have many
Pets.

I can fetch Departments and eagerly load their Persons, with :include=>
in the find statement.

But what if I want to eagerly load all the Persons, and all of the
Persons’ Pets, in, if not one single db trip, then maybe in two? In as
few as possible.

I don’t think I can do this with stock :include. Does anyone have any
advice as to how I might be able to accomplish this?

Thanks,
Jonathan


#2

you’ll want to read this…
http://snippets.dzone.com/posts/show/2089

On Aug 2, 1:38 pm, Jonathan R. <rails-mailing-l…@andreas-


#3

Wow, awesome, perfect! I had no idea a nested include was possible. That
solves so many things.

[If I wanted to actually document this, and submit it as a patch to the
official documentation… how would I do this?]

vincent fazio wrote:

you’ll want to read this…
http://snippets.dzone.com/posts/show/2089

On Aug 2, 1:38 pm, Jonathan R. <rails-mailing-l…@andreas-


#4

On Aug 2, 2007, at 2:04 PM, Jonathan R. wrote:

Wow, awesome, perfect! I had no idea a nested include was possible.
That
solves so many things.

[If I wanted to actually document this, and submit it as a patch to
the
official documentation… how would I do this?]

http://api.rubyonrails.org/classes/ActiveRecord/Associations/
ClassMethods.html

vincent fazio wrote:

you’ll want to read this…
http://snippets.dzone.com/posts/show/2089

That’s where the documentation changes would go, but you’d open a
ticket to add your [PATCH].

-Rob

Rob B. http://agileconsultingllc.com
removed_email_address@domain.invalid


#5

On 8/2/07, Jonathan R. removed_email_address@domain.invalid wrote:

[If I wanted to actually document this, and submit it as a patch to the
official documentation… how would I do this?]

watch this screen cast

http://railscasts.com/episodes/50


Edward Grant
removed_email_address@domain.invalid

RPGA #342155
CAMARILLA #US2002022579