Detecting the origin of an ActiveRecord record's destruction
In a before|after_destroy callback, you can use the destroyed_by_association method to access the association (therefore the parent record or parent record type) that is causing this record to be destroyed. This is also a handy way to tell the difference betwee a ‘direct’ destruction (widget.destroy), and a ‘dependent’ destruction has_many :widgets, dependent: :destroy`). I had a use case for this...