I have an model PointOfContact
which has_many
Systems
. From the Systems
side I want to identify the PointOfContact
as either the technical_manager
or project_manager
(or both). While still only keeping the PointOfContact
1 time in the DB.
My attempt follows:
class System < ActiveRecord::Base
belongs_to :project_manager, :class_name => 'PointOfContact'
belongs_to :technical_manager, :class_name => 'PointOfContact'
end
class PointOfContact < ActiveRecord::Base
has_many :systems
end
When I run my specs (example follows) I can correctly create the System
point of contact associations. However, the PointOfContact
is not aware of its association with System. Why is that?
@sys = System.create
@tm = PointOfContact.create
@pm = PointOfContact.create
@sys.project_manager = @pm
@sys.technical_manager = @tm
@pm.systems.should have(1).items #> expected 1 items, got 0