Forum: Ruby on Rails multiple :includes not working

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.
03d789b32a9e9c47a678f0ac173f5c13?d=identicon&s=25 Alex Treber (Guest)
on 2007-01-31 19:34
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?
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2007-01-31 19:44
(Received via mailing list)
Hi --

On Wed, 31 Jan 2007, Alex Treber 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 (http://www.manning.com/black)
    (See what readers are saying!  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)
03d789b32a9e9c47a678f0ac173f5c13?d=identicon&s=25 Alex Treber (Guest)
on 2007-01-31 20:06
> 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!
This topic is locked and can not be replied to.