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.
0f50b9a2ad85666d537d39bda49327ee?d=identicon&s=25 Jonathan Rochkind (jrochkind)
on 2007-08-02 19: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
83c468c64733d94d0e334bb02e95f8bd?d=identicon&s=25 vincent fazio (Guest)
on 2007-08-02 19: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 Rochkind <rails-mailing-l...@andreas-
0f50b9a2ad85666d537d39bda49327ee?d=identicon&s=25 Jonathan Rochkind (jrochkind)
on 2007-08-02 20: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 Rochkind <rails-mailing-l...@andreas-
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-08-02 21:05
(Received via mailing list)
On Aug 2, 2007, at 2:04 PM, Jonathan Rochkind 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 Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
46b7654dda051dcaa0c57199ce6beb13?d=identicon&s=25 Edward Grant (Guest)
on 2007-08-02 21:05
(Received via mailing list)
On 8/2/07, Jonathan Rochkind <rails-mailing-list@andreas-s.net> 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
themasternone@gmail.com

RPGA #342155
CAMARILLA #US2002022579
This topic is locked and can not be replied to.