This works, as far as finding both workers and managers for any given 
task. All CRUD look good.

I also need to sort on either the worker name or the manager name, or 
both. I can't make this work, since there is no actual field named 
"worker.name", for example.

My code looks like

Task.find(:all, :order => "worker.name, manager.name")

Since both workers and managers are actually in the Person table, I 
can't see how this could work.

Michael Pavling wrote:
> On 12 September 2010 03:47, Daniel Gayt�n <[email protected]> 
> wrote:
>> I think this could work:
>>
>> class Task < ActiveRecord::Base
>>   belongs_to :worker
>>   belongs_to :manager
>> end
> 
> That will work as long as the OP doesn't ever need a person to be a
> manager on one task, and a worker on another.
> 
> Alternatively, create two foreign keys in Tasks and link them both to
> the Person model:
> 
> class Task < ActiveRecord::Base
>   belongs_to :worker, :foreign_key => "worker_id", :class_name => 
> "Person"
>   belongs_to :manager, :foreign_key => "manager_id", :class_name => 
> "Person"
> end
> 
> No STI is required, so there's more flexibility for the Person model.

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