Topic: Table could "belong_to" one of many
I'm going talk about this in a somewhat abstract way... Note: I'm not working with gardens in my database .
We have many companies.
We have many buildings.
A company can have many buildings.
We have many plants.
A building can have many plants (which implies a company has many plants).
A company can have many plants (which are not associated with a building).
We have many pebbles.
A plant can have many pebbles (which implies a building and a company have many pebbles).
A building can have many pebbles (which are not associated with a plant, but are associated with a company).
A company can have many pebbles (which are not associated with a building or a plant).
In my database I've worked this out using 'owner' and 'owner_id' columns. However, how do I represent this in my model using :has_many and :belongs_to? Each plant doesn't necessarily belong_to a building, and the standard mapping of 'company_id' doesn't exist.