diff options
author | Aggelos Avgerinos <avgerinos@skroutz.gr> | 2016-12-07 12:36:32 +0200 |
---|---|---|
committer | Aggelos Avgerinos <evaggelos.avgerinos@gmail.com> | 2016-12-22 02:45:14 +0200 |
commit | 8f90e87b90e77bcde2a5e2e2f3764ed86a8f9639 (patch) | |
tree | da393d2d8975ec29119e97ca1588232362c1f089 | |
parent | 7336d0a269dbee21f4d38c2f48e47302e81095aa (diff) | |
download | rails-8f90e87b90e77bcde2a5e2e2f3764ed86a8f9639.tar.gz rails-8f90e87b90e77bcde2a5e2e2f3764ed86a8f9639.tar.bz2 rails-8f90e87b90e77bcde2a5e2e2f3764ed86a8f9639.zip |
[ci skip] ActiveRecord: Document order of Callbacks
-rw-r--r-- | activerecord/lib/active_record/callbacks.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index f2e3912c6e..27c43d2351 100644 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -225,6 +225,55 @@ module ActiveRecord # # This way, the +before_destroy+ gets executed before the <tt>dependent: :destroy</tt> is called, and the data is still available. # + # Also, there are cases when you want several callbacks of the same type to + # be executed in order. + # + # For example: + # + # class Topic + # has_many :children + # + # after_save :log_children + # after_save :do_something_else + # + # private + # + # def log_chidren + # # Child processing + # end + # + # def do_something_else + # # Something else + # end + # end + # + # In this case the +log_children+ gets executed before +do_something_else+. + # The same applies to all non-transactional callbacks. + # + # In case there are multiple transactional callbacks as seen below, the order + # is reversed. + # + # For example: + # + # class Topic + # has_many :children + # + # after_commit :log_children + # after_commit :do_something_else + # + # private + # + # def log_chidren + # # Child processing + # end + # + # def do_something_else + # # Something else + # end + # end + # + # In this case the +do_something_else+ gets executed before +log_children+. + # # == \Transactions # # The entire callback chain of a {#save}[rdoc-ref:Persistence#save], {#save!}[rdoc-ref:Persistence#save!], |