I have Worker, Manager, and Title models in Rails 2.x. There is also a JOIN table that has only worker_id, manager_id, and title_id (no explicit model for this). Because of this JOIN table (and not having a model for it), I assume I have to have the following:
In the Worker model, I have:
Worker
has_and_belongs_to_many :managers
has_and_belongs_to_many :titles
But, in reality, the relationship is that Worker can only have 1 Manager, but many Titles. Also, many Workers have the same Manager.
Some sample data to illustrate the relationship:
Worker | Title | Manager
Tom | A | M1
Tom | B | M1
Bob | A | M2
Pam | C | M1
Is the above Worker model "correct"? When creating a new Worker (and all their relationships), I do:
worker = Worker.new("A")
title = "B"
manager = "C"
worker.titles << title
worker.managers << manager
worker.save
When I do this, I get the following in my database:
Worker | Title | Manager
A | B | null
A | null | C
I would like to get:
Worker | Title | Manager
A | B | C