Hi, I''m trying to find all of the products that have parts supplied by the given supplier''s name: @products=Product.find :all, :include=>["company","parts"], :joins=>"inner join suppliers_to_parts stp on stp.part = parts.id inner join suppliers s on s.id stp.supplier", :conditions=>["s.name = ?",name] The problem is that the supplier''s name is not returned, and :select doesn''t work when :include is used. Of course I could use all :joins, or even find_by_sql, but I''d like to have my object hierarchy (well, as much as rails will allow) returned instead of a single object with a bunch of attributes. Is it possible to achieve this some other way? Thank You --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rick Olson
2007-Jun-19 08:30 UTC
Re: ActiveRecord::Base.find returning columns from :joins
On 6/18/07, dutone <dutone-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> > Hi, > > I''m trying to find all of the products that have parts supplied by > the given supplier''s name: > > > @products=Product.find :all, :include=>["company","parts"], > :joins=>"inner join suppliers_to_parts > stp on stp.part = parts.id > inner join suppliers s on s.id > stp.supplier", > :conditions=>["s.name = ?",name] > > The problem is that the supplier''s name is not returned, and :select > doesn''t work when :include is used. > Of course I could use all :joins, or even find_by_sql, but I''d like to > have my object hierarchy (well, as much as rails will allow) returned > instead of a single object with a bunch of attributes. > > Is it possible to achieve this some other way? > > Thank YouNope, eager includes clobber the :select option because of the way it generates it''s own select clause. -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.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 -~----------~----~----~----~------~----~------~--~---
Ryan Sobol
2007-Jun-19 15:11 UTC
Re: ActiveRecord::Base.find returning columns from :joins
I was having the same issue earlier this week -- innner joining two tables while trying to return a set of AR objects for one of those tables. Here''s what I did in my project to get it to work. http://pastie.caboo.se/71756 Granted I''m using paginate() rather than find(), but it should probably work for you. I think the important thing here is the not use the :include option. As Rick confirmed, it clobbers the :select option with it''s own value. -- RYAN On Jun 18, 9:41 pm, dutone <dut...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:> Hi, > > I''m trying to find all of the products that have parts supplied by > the given supplier''s name: > > @products=Product.find :all, :include=>["company","parts"], > :joins=>"inner join suppliers_to_parts > stp on stp.part = parts.id > inner join suppliers s on s.id > stp.supplier", > :conditions=>["s.name = ?",name] > > The problem is that the supplier''s name is not returned, and :select > doesn''t work when :include is used. > Of course I could use all :joins, or even find_by_sql, but I''d like to > have my object hierarchy (well, as much as rails will allow) returned > instead of a single object with a bunch of attributes. > > Is it possible to achieve this some other way? > > Thank You--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jun 19, 8:11 am, Ryan Sobol <ryanso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I was having the same issue earlier this week -- innner joining two > tables while trying to return a set of AR objects for one of those > tables. Here''s what I did in my project to get it to work. > > http://pastie.caboo.se/71756Yup, I''m afraid thats what i''ll have to do. Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---