Multiple :includes not working


#1

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?


#2

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 (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)


#3

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!