Multiple :includes not working

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?

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)

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs