I’m new to Ruby on Rails and I’m trying to model my table relationships.
To simplify the problem, let’s say I have 3 tables:
— Customer (id, address_id, …)
— Employee (id, address_id, …)
— Address (id, …)
Would the Address model have the following?
has_one :customer
has_one :employee
I know this is true in the case of a single relationship, but I couldn’t find any examples where there were two “has_one” relationships like that.
You should use polymorphic associations as shown below.
Now you can do the following:
OR