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.

Of course, it is possible to do this  in SQL (i.e., sort tasks based on 
the names in the People table, with separate sorts for managers and 
workers).

SELECT t.job_number, p1.name, p2.name FROM tasks AS t LEFT JOIN people 
AS p1 ON t.worker_id = p1.id LEFT JOIN people AS p2 ON t.manager_id = 
p2.id ORDER BY p1.name, p2.name

Here, p1.name will be the worker name, and p2.name will be the manager 
name.

The question is, should I struggle to generate this through ActiveRecord 
constructs, or just call the raw SQL? If there is a reasonable way to do 
this via AR, I'd rather do that, but I have no fear of the raw call.

Michael Pavling wrote:

> Try :
>  Task.find(:all, :include => [:worker, :manager], :order =>
> "worker.name, manager.name")
> 
> although that's off the top of my head and I'm not able to look up the
> syntax of multiple includes right this second.
> 
> HTH

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to