Flowdock
method

before_destroy

Importance_3
Ruby on Rails latest stable (v4.0.2) - 2 notes - Class: ActiveRecord::Callbacks

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v2.3.8) is shown here.

before_destroy() public

Is called before Base.destroy.

Note: If you need to destroy or nullify associated records first, use the :dependent option on your associations.

Show source
Register or log in to add new notes.
July 17, 2008
7 thanks

Where you declare before_destroy matters

Beware that where you declare a before_destroy callback matters if you have any “acts_as” type declarations, that also declare before_destroy callbacks. A good example is the acts_as_nested_set. If you specify acts_as_nested_set prior to your before_destroy, then acts_as_nested_set will go through and destroy all children first, then your callback will run (at which point children will be empty). Thus, if your before_destroy callback needs to examine the children, it will not work properly. Putting your before_destroy callback ahead of acts_as_nested_set or anything else that declares a before_destroy is key in such cases.