ActiveRecord::Base.find returning columns from :joins

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

On 6/18/07, dutone [email protected] wrote:

                            inner join suppliers s on s.id =

Thank You

Nope, eager includes clobber the :select option because of the way it
generates it’s own select clause.


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

On Jun 19, 8:11 am, Ryan S. [email protected] 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/71756

Yup, I’m afraid thats what i’ll have to do.
Thanks

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

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