I've got a record in my Rails app with an after_destroy
hook that needs to be aware of why the record gets destroyed. More specifically, if the record is being destroyed in a cascade because its parent says dependent: :destroy
, it needs to do things differently than if the record was individually destroyed.
What I tried to do is to see if its parent was destroyed?
, only to figure out that dependent: :destroy
callbacks are done before the parent is destroyed. Which makes sense because it should be able to fail. (i.e. restrict).
So, how do I do this?
destroyed?
, only to figure out thatdependent: :destroy
callbacks are done before the parent is destroyed. In other words: that is useless, the paren't can't be destroyed as the dependent callback is issued before the parent gets destroyed.