Re: [Rails] Re: Re: "belongs_to" two different people
On 15 September 2010 22:36, Brian Ablaza <lists@ruby-forum.com> wrote:
> No luck. The query ends with "ORDER BY worker.name, manager.name", and
> as these are not columns in the Tasks table, it won't work.
Sorry, my quick answer was hideously wrong to assume the joins that AR
would create would be called "worker" and "manager".
I've just tried this on a table of mine, which has two associations to
a "people" table, one as :person, and one as :owner, and the following
works:
Enrollment.all(:include => [:person, :owner], :order =>
"owners_enrollments.lastname, people.lastname")
Please note that I discovered the table alias depends on the position
in the array of includes (for instance if I had ":include => [:owner,
:person]", the alias was different. But if you determine (I used the
console to troubleshoot) what the alias is, then your query should
work as you want as long as you don't fiddle with it!
--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home