Jonathan Rochkind
2007-Aug-02 17:38 UTC
Best way to eager load accross multiple relationships?
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
vincent fazio
2007-Aug-02 17:45 UTC
Re: Best way to eager load accross multiple relationships?
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- s.net> wrote:> 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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jonathan Rochkind
2007-Aug-02 18:04 UTC
Re: Best way to eager load accross multiple relationships?
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--- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-Aug-02 18:58 UTC
Re: Best way to eager load accross multiple relationships?
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/Associations/ ClassMethods.html> vincent fazio wrote: >> you''ll want to read this... >> http://snippets.dzone.com/posts/show/2089That''s where the documentation changes would go, but you''d open a ticket to add your [PATCH]. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
Edward Grant
2007-Aug-02 19:04 UTC
Re: Best way to eager load accross multiple relationships?
On 8/2/07, Jonathan Rochkind <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org RPGA #342155 CAMARILLA #US2002022579 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---