Emma wrote: [...] > 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.
Right -- because there's nothing in your code saying that the first address should be deleted. How is Rails to know that you don't want to have the first Address available? [...] > > 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. I think this is actually the correct approach. As far as the schema is concerned, you don't really want a separate Address table. If the DB supported Address columns, of course you'd do it that way; since it doesn't, composed_of fakes this functionality for you. You can use modules or AR subclasses to cut down on code repetition. Alternatively, you could write a method that creates a new Address and deletes the old one explicitly. > > How can I solve this? Any suggestions? > Thanks in advance. Best, -- Marnen Laibow-Koser http://www.marnen.org mar...@marnen.org -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---