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.
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.
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.