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

**URL:** <https://www.ruby-forum.com/t/nested-find-all-include-statements/80339>\
**Category:** Rails\
**Created:** [March 13, 2006, 2:43pm UTC](https://www.ruby-forum.com/t/nested-find-all-include-statements/80339 "2006-03-13T14:43:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 13, 2006, 2:43pm UTC](https://www.ruby-forum.com/t/nested-find-all-include-statements/80339/1 "2006-03-13T14:43:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 13, 2006, 2:59pm UTC](https://www.ruby-forum.com/t/nested-find-all-include-statements/80339/2 "2006-03-13T14:59:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 13, 2006, 3:16pm UTC](https://www.ruby-forum.com/t/nested-find-all-include-statements/80339/3 "2006-03-13T15:16:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 13, 2006, 11:16pm UTC](https://www.ruby-forum.com/t/nested-find-all-include-statements/80339/4 "2006-03-13T23:16:05Z")

</div>

Edge rails supports cascading eager loading. You would do:

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

-Jonathan.

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 13, 2006, 8:43pm UTC](https://www.ruby-forum.com/t/nested-find-all-include-statements/80339/5 "2006-03-13T20:43:04Z")

</div>

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

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000754)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

Alain

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 14, 2006, 11:01am UTC](https://www.ruby-forum.com/t/nested-find-all-include-statements/80339/6 "2006-03-14T11:01:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 14, 2006, 11:43am UTC](https://www.ruby-forum.com/t/nested-find-all-include-statements/80339/7 "2006-03-14T11:43:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 14, 2006, 9:33am UTC](https://www.ruby-forum.com/t/nested-find-all-include-statements/80339/8 "2006-03-14T09:33:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![joergd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/51bf81/32.png) [@joergd](https://www.ruby-forum.com/u/joergd)\
**Post date:** [March 14, 2006, 2:07pm UTC](https://www.ruby-forum.com/t/nested-find-all-include-statements/80339/9 "2006-03-14T14:07:37Z")

</div>

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.
