# Multiple :includes not working

**URL:** <https://www.ruby-forum.com/t/multiple-includes-not-working/84042>\
**Category:** Rails\
**Created:** [January 31, 2007, 7:34pm UTC](https://www.ruby-forum.com/t/multiple-includes-not-working/84042 "2007-01-31T19:34:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![canner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f9ae1b/32.png) [@canner](https://www.ruby-forum.com/u/canner)\
**Post date:** [January 31, 2007, 7:34pm UTC](https://www.ruby-forum.com/t/multiple-includes-not-working/84042/1 "2007-01-31T19:34:58Z")

</div>

Can you run a query and have multiple includes? I am able to do this  
through joins, but was trying to get it to work with includes.

This works  
a.find(:all, :include =\> :b)  
and  
a.find(:all, :include =\> :c)

but  
a.find(:all, :include =\> :b, :include =\> :c)  
does not. It only returns the join of a and c (or the last table in the  
list)

The mappings between tables should be correct, a has b\_id and c\_id  
columns.

Any ideas on how this can be done?

---

<div class="post-metadata">

**Author:** ![canner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f9ae1b/32.png) [@canner](https://www.ruby-forum.com/u/canner)\
**Post date:** [January 31, 2007, 7:44pm UTC](https://www.ruby-forum.com/t/multiple-includes-not-working/84042/2 "2007-01-31T19:44:55Z")

</div>

Hi –

On Wed, 31 Jan 2007, Alex T. wrote:

> a.find(:all, :include =\> :b, :include =\> :c)  
> does not. It only returns the join of a and c (or the last table in the  
> list)

You have to do:

:include =\> [:b, :c]

i.e., an array. Remember that all that :key =\> value stuff is  
actually a hash. If you give two :include keys, one will get  
clobbered.

David

–  
Q. What is THE Ruby book for Rails developers?  
A. RUBY FOR RAILS by David A. Black ([Ruby for Rails](http://www.manning.com/black))  
(See what readers are saying! [http://www.rubypal.com/r4rrevs.pdf](http://www.rubypal.com/r4rrevs.pdf))  
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?  
A. Ruby Power and Light, LLC ([http://www.rubypal.com](http://www.rubypal.com))

---

<div class="post-metadata">

**Author:** ![canner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f9ae1b/32.png) [@canner](https://www.ruby-forum.com/u/canner)\
**Post date:** [January 31, 2007, 8:06pm UTC](https://www.ruby-forum.com/t/multiple-includes-not-working/84042/3 "2007-01-31T20:06:59Z")

</div>

> You have to do:
> 
> :include =\> [:b, :c]
> 
> i.e., an array. Remember that all that :key =\> value stuff is  
> actually a hash. If you give two :include keys, one will get  
> clobbered.

Worked great, glad it was just something simple!
