Including children's children?

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 J.
E: [email protected]
O: 800-341-6826
M: 817-229-4258

On Thursday, July 20, 2006, at 5:21 PM, Ben J. wrote:

Ben J.
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Apparently like this…

results = A.find params[:id], :include => {:b=>:c}

_Kevin
www.sciwerks.com

Are you serious? :b => :c??

On 20 Jul 2006 22:39:42 -0000, Kevin O. <

Yes

-Ezra

On Jul 20, 2006, at 6:52 PM, Ajaya A. wrote:

Ezra Z. 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 M.

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

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.

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”

But will this sort directly from the preloaded arrays or will they
generate new SQL statements if I did, for instance, @books.pages ?

Ezra Z. 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??

aj

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs