Saturday, September 11, 2010

[Rails] "belongs_to" two different people

I have a People table and a Tasks table. Some People are Managers, some
are Workers. Each Task has a Manager and a Worker.

How do I define the relationships? I tried a STI setup, where Managers
and Workers inherit from People, and People has a type column. In my
Task table, I have worker_id and manager_id rows. Then:

task belongs_to worker
task belongs_to manager
worker has_many tasks
manager has_many tasks

But when I ask for task.worker, or task.manager, it throws an error.

How can I do this without separate Worker and Manager tables?
--
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 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


Real Estate