I have the following association:
class Parent < ActiveRecord::Base
has_many :children, :dependent => :destroy
before_destroy :do_some_stuff
end
class Child < ActiveRecord::Base
belongs_to :parent
before_destroy :do_other_stuff
end
I would like to know in do_other_stuff if the destruction has been fired by dependent => destroy or not because part of it would/will be done in do_some_stuff
I tried parent.destroyed?
, parent.marked_for_destruction?
, parent.frozen?
but nothing work :/
any ideas?
You can use the association callbacks ( before_remove
or after_remove
)
class Parent < ActiveRecord::Base
has_many :children, :dependent => :destroy, :before_remove => :do_foo
before_destroy :do_bar
def do_bar
end
def do_foo
end
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