I’m having trouble with this model:
class Person < AR::B
belongs_to :shipping_address, :class_name => ‘Address’
belongs_to :billing_address, :class_name => ‘Address’
class Address < AR::B
The problem is that I want Address to be a Value Object (as in DDD),
and if I do this:
p = Person.create :shipping_address => Address.new(…)
and later I change the address:
p.shipping_address = Address.new(…)
the first address object doesn’t get deleted from the DB. It becomes
I can inverse the association and use a has_one but then I have to put
two foreign keys in the address table… and that could be a problem
because there are other models that have addresses.
Another option could be to model both associations as composed_of but
then I have to put all of the address table columns on the people
table, and repeat this on the other models that have addresses too.
How can I solve this? Any suggestions?
Thanks in advance.