diff options
Diffstat (limited to 'activerecord/lib/active_record/callbacks.rb')
-rw-r--r-- | activerecord/lib/active_record/callbacks.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index 3aa0b8f1b5..4a2ec5bf95 100644 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -22,7 +22,7 @@ module ActiveRecord # * (8) <tt>after_save</tt> # # That's a total of eight callbacks, which gives you immense power to react and prepare for each state in the - # Active Record lifecycle. The sequence for calling <tt>Base#save</tt> an existing record is similar, except that each + # Active Record lifecycle. The sequence for calling <tt>Base#save</tt> for an existing record is similar, except that each # <tt>_on_create</tt> callback is replaced by the corresponding <tt>_on_update</tt> callback. # # Examples: @@ -262,6 +262,10 @@ module ActiveRecord # Is called _after_ <tt>Base.save</tt> on new objects that haven't been saved yet (no record exists). # Note that this callback is still wrapped in the transaction around +save+. For example, if you # invoke an external indexer at this point it won't see the changes in the database. + # + # class Contact < ActiveRecord::Base + # after_create { |record| logger.info( "Contact #{record.id} was created." ) } + # end def after_create() end def create_with_callbacks #:nodoc: return false if callback(:before_create) == false @@ -272,11 +276,19 @@ module ActiveRecord private :create_with_callbacks # Is called _before_ <tt>Base.save</tt> on existing objects that have a record. + # + # class Contact < ActiveRecord::Base + # before_update { |record| logger.info( "Contact #{record.id} is about to be updated." ) } + # end def before_update() end # Is called _after_ <tt>Base.save</tt> on existing objects that have a record. # Note that this callback is still wrapped in the transaction around +save+. For example, if you # invoke an external indexer at this point it won't see the changes in the database. + # + # class Contact < ActiveRecord::Base + # after_update { |record| logger.info( "Contact #{record.id} was updated." ) } + # end def after_update() end def update_with_callbacks(*args) #:nodoc: @@ -326,6 +338,10 @@ module ActiveRecord # # Note: If you need to _destroy_ or _nullify_ associated records first, # use the <tt>:dependent</tt> option on your associations. + # + # class Contact < ActiveRecord::Base + # after_destroy { |record| logger.info( "Contact #{record.id} is about to be destroyed." ) } + # end def before_destroy() end # Is called _after_ <tt>Base.destroy</tt> (and all the attributes have been frozen). |