I posted a similar email, earlier in the week, but I still must not be
I have a customer that aggregates two addresses; a shipping address
and a billing address. Addresses can also be referenced by other
objects in a similar way, so I would really like to avoid putting the
keys referencing the customer or other objects in the addresses table.
Addresses are exclusively referenced by parent objects and a
many-to-many association is not appropriate.
Ideally I would like the customers table to use a shipping_address_id
and a billing_address_id to reference the aggregate addresses. For
illustration purposes, another object, company might have a
main_address_id, an after_hours_address_id and a weekend_address_id.
In order to keep the keys in the customer table the belongs_to
statements are in the customer model and the has_one statement is in
the address model.
This creates the structure I am after, but not the behavior. The
customer is really the parent object, when I delete the customer I
want it to cascade to addresses, etc.
It seems like I am writing more code than I should to propagate
updates, etc to addresses. Am I totally off base? Any guidance would
be greatly appreciated.