I have a problem with one of my models. The parent object has 2 polymorphic relationships both specifying :dependent => :destroy. This all works fine until you attempt to delete the parent and the parent’s before_destroy callback returns false. When the parent’s before_destroy callback returns false, the parent is not deleted, but the transaction is still committed so all of the objects from the polymorphic relationships are destroyed. This is obviously not desirable. I have verified that the call back is returning false. Is there something I am missing or is this just normal. I can remove the :dependent => :destroy and place the relevant code in my before_destroy callback, but this seems to defeat the purpose of :dependent and would get really messy on objects with many dependencies.
Here is the abbreviated code in question:
class Location < AbstractBase
has_one :address, :as => :addressed, :dependent => :destroy
has_one :contact, :as => :contactable, :dependent => :destroy
class AbstractBase < ActiveRecord::Base