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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Jan-31 18:42 UTC
Re: multiple :includes not working
Hi -- On Wed, 31 Jan 2007, Alex Treber wrote:> > 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)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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---