Nested find(:all, :include => []) statements


#1

Is there a way for me to do:

OrderItem.find(:all, :include => [:user, :product => [:supplier]]

So I don’t have a supplier_id on my order_item, but have it on my
product, which is part of order_item.

Joerg


#2

I think this is only possible in edgerails. Alternatively, you can use
find_by_sql
Joerg D. wrote:

Is there a way for me to do:

OrderItem.find(:all, :include => [:user, :product => [:supplier]]

So I don’t have a supplier_id on my order_item, but have it on my
product, which is part of order_item.

Joerg


#3

Running EdgeRails. Would you know what the syntax is?

Cheltis wrote:

I think this is only possible in edgerails. Alternatively, you can use
find_by_sql
Joerg D. wrote:

Is there a way for me to do:

OrderItem.find(:all, :include => [:user, :product => [:supplier]]

So I don’t have a supplier_id on my order_item, but have it on my
product, which is part of order_item.

Joerg


#4

Edge rails supports cascading eager loading. You would do:

OrderItem.find(:all, :include => [:user, { :product => :supplier } ]

-Jonathan.


#5

Joerg

> Is there a way for me to ..

I’m not sure I understand your example, but if you’re looking for nested
finds, the new way is to use
with_scope

http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000754

Alain


#6

The syntax for cascading eager loading does not work for me:

It ends up looking for an association called :productsupplier. I’ve
tried it using quotes instead, and I get the same problem.

Have you got this working? I am using an EdgeRails version a few days
old -> the current one throws an error starting WEBrick.

Joerg D. wrote:

Ah, ‘cascading eager loading’ … that’s what I was looking for!
Cool - thanks.

Jonathan V. wrote:

Edge rails supports cascading eager loading. You would do:

OrderItem.find(:all, :include => [:user, { :product => :supplier } ]

-Jonathan.


#7

It was added in r3769, so anything after that should work.

It works fine for me. Double check you’ve got the correct names for the
associations you are including.

-Jonathan.


#8

Ah, ‘cascading eager loading’ … that’s what I was looking for!
Cool - thanks.

Jonathan V. wrote:

Edge rails supports cascading eager loading. You would do:

OrderItem.find(:all, :include => [:user, { :product => :supplier } ]

-Jonathan.


#9

It’s working thanks - got the latest version and commented out some
lines in the server.rb file to make WEBrick start up again.

Jonathan V. wrote:

It was added in r3769, so anything after that should work.

It works fine for me. Double check you’ve got the correct names for the
associations you are including.

-Jonathan.