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.
34791e1d8c4def65f9b93294638a7e04?d=identicon&s=25 Joerg Diekmann (joergd)
on 2006-03-13 14: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
C5b6840775639751136a320d3cb47b12?d=identicon&s=25 Cheltis (Guest)
on 2006-03-13 14:59
I think this is only possible in edgerails. Alternatively, you can use
find_by_sql
Joerg Diekmann 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
34791e1d8c4def65f9b93294638a7e04?d=identicon&s=25 Joerg Diekmann (joergd)
on 2006-03-13 15: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 Diekmann 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
0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2006-03-13 20: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
631d1677786f0725da6ccee46043686e?d=identicon&s=25 Jonathan Viney (Guest)
on 2006-03-13 23:16
(Received via mailing list)
Edge rails supports cascading eager loading. You would do:

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

-Jonathan.
34791e1d8c4def65f9b93294638a7e04?d=identicon&s=25 Joerg Diekmann (joergd)
on 2006-03-14 09:33
Ah, 'cascading eager loading' ... that's what I was looking for!
Cool - thanks.

Jonathan Viney wrote:
> Edge rails supports cascading eager loading. You would do:
>
> OrderItem.find(:all, :include => [:user, { :product => :supplier } ]
>
> -Jonathan.
34791e1d8c4def65f9b93294638a7e04?d=identicon&s=25 Joerg Diekmann (joergd)
on 2006-03-14 11: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 Diekmann wrote:
> Ah, 'cascading eager loading' ... that's what I was looking for!
> Cool - thanks.
>
> Jonathan Viney wrote:
>> Edge rails supports cascading eager loading. You would do:
>>
>> OrderItem.find(:all, :include => [:user, { :product => :supplier } ]
>>
>> -Jonathan.
631d1677786f0725da6ccee46043686e?d=identicon&s=25 Jonathan Viney (Guest)
on 2006-03-14 11: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.
34791e1d8c4def65f9b93294638a7e04?d=identicon&s=25 Joerg Diekmann (joergd)
on 2006-03-14 14: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 Viney 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.