If I have a table called enrollments and this is my current basic enrollment setup:
class Enrollment < ActiveRecord::Base
belongs_to :father
belongs_to :mother
belongs_to :child
end
class Father < ActiveRecord::Base
has_many :enrollments
has_many :children
validates :first_name, :presence => true
validates :last_name, :presence => true
end
Now I want to add a guardian_1_id and a guardian_2_id to theenrollments table. How would I set that up?
You might be best off using a polymorphic association, e.g.
This shoudl give you some flexibility in terms of whether there are 1, 2, or more guardians per situation. Also, you could add validation that caps it at two.