When you say, a Company has_one location, you imply that it's upto the Locations table to have the FK. A has_one
relationship is a one-to-one relationship and in your case it makes perfect sense to add a company_id
to the Locations
table.
A belongs_to
relationship (i.e. Location belongs_to Company) won't make sense here, because that will allow you to link multiple companies to one location. Unless, of course, you want to allow that, lose the has_one
relationship on the Company
model and add a belongs_to
relationship on the Location
model instead.
Update
company has_many_and_belongs_to location
would be a better choice of relationship, given that a company can have many locations and one location can have many companies.
I would just add an extra column in the locations table (is_headquarter) to identify a company's headquarter.