Ruby 2.1.2 and Rails 4: I have a parent object and a child object. I have a before_destroy
callback for the child object that may prevent its destruction based on a flag. However, I also need its parent to be able to destroy it via a dependent: :destroy
relationship.
How can I check the source of its destruction in my validation?
I found marked_for_destruction?
and a host of related questions here, but none seem concerned with the before_destroy
callback, which runs before the object (or even its parent) are marked for destruction. I've been prying through what's accessible in the callback for a while now and can't seem to find anything.
I could obviously go with dependent: :delete
instead, although that seems like it misses the point. I'm sure I could come up with something else like doing a before_destroy on the parent, and then calling a monkey-patched destroy
method with some arguments or some such thing, but it also seems to miss the point.
Any suggestions? Is there some property on the parent that I'm missing, or a way to trace the destroy
call's source or something? Thanks in advance!