In our application we've overridden the ActiveRecord destroy method so that our records do not get deleted (so the user can undelete). Like so:
def destroy
self.is_deleted = true
self.save
freeze
end
However, this seems to have disabled the dependent destroy on our has_many
relationships. In other words, if destroy
is called on a parent object, the child objects of has_many
do not get destroyed (they don't get deleted, i.e, SQL 'DELETE...
', nor is the overridden destroy
-method called).
How do I trigger the destruction of the child objects.
Thanks!
You need to trigger the destroy callback.
def destroy
self.is_deleted = true
self.save
run_callbacks :destroy
freeze
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With