a has many b''s b has many c''s results = A.find params[:id], :include => :b How do you also make sure the b''s include the c''s? Thanks for your help. Thank You, Ben Johnson E: bjohnson@contuitive.com O: 800-341-6826 M: 817-229-4258 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060720/1c277961/attachment.html
On Thursday, July 20, 2006, at 5:21 PM, Ben Johnson wrote:>a has many b''s >b has many c''s > >results = A.find params[:id], :include => :b > >How do you also make sure the b''s include the c''s? > >Thanks for your help. > >Thank You, >Ben Johnson >E: bjohnson@contuitive.com >O: 800-341-6826 >M: 817-229-4258 > > > > > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails >Apparently like this... results = A.find params[:id], :include => {:b=>:c} _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.
Are you serious? :b => :c?? On 20 Jul 2006 22:39:42 -0000, Kevin Olbrich < devlists-rubyonrails@devlists.com> wrote:> > > On Thursday, July 20, 2006, at 5:21 PM, Ben Johnson wrote: > >a has many b''s > >b has many c''s > > > >results = A.find params[:id], :include => :b > > > >How do you also make sure the b''s include the c''s? > > > >Thanks for your help. > > > >Thank You, > >Ben Johnson > >E: bjohnson@contuitive.com > >O: 800-341-6826 > >M: 817-229-4258 > > > > > > > > > > > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > Apparently like this... > > results = A.find params[:id], :include => {:b=>:c} > > _Kevin > www.sciwerks.com > > -- > Posted with http://DevLists.com. Sign up and save your mailbox. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060720/79cda91a/attachment.html
Yes -Ezra On Jul 20, 2006, at 3:53 PM, Michael Genereux wrote:> Are you serious? :b => :c?? > > On 20 Jul 2006 22:39:42 -0000, Kevin Olbrich <devlists- > rubyonrails@devlists.com > wrote: > > On Thursday, July 20, 2006, at 5:21 PM, Ben Johnson wrote: > >a has many b''s > >b has many c''s > > > >results = A.find params[:id], :include => :b > > > >How do you also make sure the b''s include the c''s? > > > >Thanks for your help. > > > >Thank You, > >Ben Johnson > >E: bjohnson@contuitive.com > >O: 800-341-6826 > >M: 817-229-4258 > > > > > > > > > > > >_______________________________________________ > >Rails mailing list > >Rails@lists.rubyonrails.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > Apparently like this... > > results = A.find params[:id], :include => {:b=>:c} > > _Kevin > www.sciwerks.com > > -- > Posted with http://DevLists.com. Sign up and save your mailbox. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060720/d2740abe/attachment.html
Ezra Zygmuntowicz wrote:> Yes > > -EzraIsn''t it better to get parent first and get the child rows referencing them parent.children rather then doing a big join?? aj -- Posted via http://www.ruby-forum.com/.
On Jul 20, 2006, at 6:52 PM, Ajaya Agrawalla wrote:> Ezra Zygmuntowicz wrote: >> Yes >> >> -Ezra > > Isn''t it better to get parent first and get the child rows referencing > them parent.children rather then doing a big join??That way lies the n+1 problem that people mention when discussing objective-relational frameworks. It''s a lot harder on the DB to do it that way. -- -- Tom Mornini
However, it seemed to me that doing :includes or nested :includes organizes the children arrays by ID, or at least not your specified '':has_many ..., :order => ...'' attribute in your model. -caleon On Jul 20, 2006, at 7:08 PM, Tom Mornini wrote:> On Jul 20, 2006, at 6:52 PM, Ajaya Agrawalla wrote: > >> Ezra Zygmuntowicz wrote: >>> Yes >>> >>> -Ezra >> >> Isn''t it better to get parent first and get the child rows >> referencing >> them parent.children rather then doing a big join?? > > That way lies the n+1 problem that people mention when discussing > objective-relational frameworks. > > It''s a lot harder on the DB to do it that way. > > -- > -- Tom Mornini > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Actually, having said that, does anyone know how to retain a model''s ordering scheme while using nested include statements? Example of the nested statement would be: :include => {:books => {:pages => {:paragraphs => :lines} }} Thanks in advance. On Jul 20, 2006, at 8:23 PM, Colin Chun wrote:> However, it seemed to me that doing :includes or nested :includes > organizes the children arrays by ID, or at least not your specified > '':has_many ..., :order => ...'' attribute in your model. > > -caleon > > On Jul 20, 2006, at 7:08 PM, Tom Mornini wrote: > >> On Jul 20, 2006, at 6:52 PM, Ajaya Agrawalla wrote: >> >>> Ezra Zygmuntowicz wrote: >>>> Yes >>>> >>>> -Ezra >>> >>> Isn''t it better to get parent first and get the child rows >>> referencing >>> them parent.children rather then doing a big join?? >> >> That way lies the n+1 problem that people mention when discussing >> objective-relational frameworks. >> >> It''s a lot harder on the DB to do it that way. >> >> -- >> -- Tom Mornini >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Colin Chun wrote:> does anyone know how to retain a model''s > ordering scheme while using nested include statements? > :include => {:books => {:pages => {:paragraphs => :lines} }}I think you can use :order as you normally would: :order => "books.name asc, pages.number asc" -- Posted via http://www.ruby-forum.com/.
But will this sort directly from the preloaded arrays or will they generate new SQL statements if I did, for instance, @books.pages ? On Jul 21, 2006, at 6:56 AM, Dr Nic wrote:> Colin Chun wrote: >> does anyone know how to retain a model''s >> ordering scheme while using nested include statements? >> :include => {:books => {:pages => {:paragraphs => :lines} }} > > I think you can use :order as you normally would: > > :order => "books.name asc, pages.number asc" > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails