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'
end

class Address < AR::B
end

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(...)
p.save

the first address object doesn't get deleted from the DB. It becomes
an orphan.

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.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to