On Saturday 25 July 2009, Matt Jones wrote:
> You can also use the methods included from ActiveRecord::Dirty on the
> foreign key fields; in your case, you'd have an after_save callback
> like this (on Person):
>
> after_save :cleanup_addresses
>
> def cleanup_addresses
>   Address.destroy(shipping_address_id_was) if
> shipping_address_id_changed? && shipping_address_id_was
>   Address.destroy(billing_address_id_was) if
> billing_address_id_changed? && billing_address_id_was
> end

Matt, have you tried this code? Specifically, are you sure that the 
dirty states have not already been reset by the time the after_save 
callback is invoked? That was my concern when I suggested using a 
before_save callback in a parallel post.

Michael

-- 
Michael Schuerig
mailto:[email protected]
http://www.schuerig.de/michael/


--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to