6

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!

1 Answers1

6

You need to trigger the destroy callback.

def destroy
  self.is_deleted = true
  self.save
  run_callbacks :destroy
  freeze
end
vise
  • 12,713
  • 11
  • 52
  • 64