I have a User and a Shop model (Rails 5.2) that should have multiple locations like ship_location, bill_location... How can I use the same Location multiple times for this?
The User and Shop model could look something like this
class User has_one :ship_location has_one :bill_location end class Shop has_one :ship_location has_one :bill_location has_one :contact_location end But I can't figure out how the Location model should look like. It should be as abstract as possible, so that I don't have to define a new relationship and/or models when the Location is used for another model.
I guess I have to use some sort of polymorphism:
class Location # location has owner_id and owner_type belongs_to :owner, polymorphic: true end But this doesn't work, because user.ship_location is ambiguous (it would look for owner_type == "User" and owner_id == 1 but because there is also a bill_location with the same owner_type and owner_id, it doesn't work).
Do I need to create separate models for this, that share the same table?