Forum: Ruby on Rails Best way to eager load accross multiple relationships?

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.
Jonathan R. (Guest)
on 2007-08-02 21:38
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
vincent fazio (Guest)
on 2007-08-02 21:45
(Received via mailing list)
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-
Jonathan R. (Guest)
on 2007-08-02 22:04
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-
Rob B. (Guest)
on 2007-08-02 23:05
(Received via mailing list)
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/As...
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
Edward Grant (Guest)
on 2007-08-02 23:05
(Received via mailing list)
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
This topic is locked and can not be replied to.