Forum: Ruby on Rails Nested find(:all, :include => []) statements

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.
Joerg D. (Guest)
on 2006-03-13 15:43
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
Cheltis (Guest)
on 2006-03-13 15:59
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
Joerg D. (Guest)
on 2006-03-13 16:16
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
Alain R. (Guest)
on 2006-03-13 21:43
(Received via mailing list)
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/Ba...

Alain
Jonathan V. (Guest)
on 2006-03-14 00:16
(Received via mailing list)
Edge rails supports cascading eager loading. You would do:

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

-Jonathan.
Joerg D. (Guest)
on 2006-03-14 10:33
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.
Joerg D. (Guest)
on 2006-03-14 12:01
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.
Jonathan V. (Guest)
on 2006-03-14 12:43
(Received via mailing list)
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.
Joerg D. (Guest)
on 2006-03-14 15:07
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.
This topic is locked and can not be replied to.