How do i get two “has_one” relationships to the same table?
I have an audit table with fields auditor_id and manager_id that both
link to the people table:
AUDIT:
id
name
datecreated
auditor_id
manager_id
PEOPLE:
id
name
I have no idea how to link both fields from audit to people?? any
ideas??
I’m pulling my hair out trying to figure this out, please help!!
I know that if it were just one field then i’d call the field person_id.
What do i call a second field linking to the same table ???
person_id_2???
please help.
I think the trick is getting the has_many and belong_to in the correct
places. Since Audit references the People class, it is Audit that
belongs to
the People. I hope I got this right way around. I think this should work
(untested code).
class Manager < Person
has_many :audits #manager specific functionality
end
Not going to cut it. This logically implies that a person can be an
Auditor or a Manager but not both and identifes them in the Person
record (by the mandatory ‘type’ field for STI.