Skip to content

Commit a2b9e92

Browse files
zzakConfusedVorlon
andcommitted
Document callback deduplication with regards to ActiveRecord::Transaction
/cc rails#51184, rails#51171, rails#40648, rails#48910 Co-authored-by: Rob Jonson <[email protected]>
1 parent dd88c7e commit a2b9e92

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

activerecord/lib/active_record/transactions.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,27 @@ module Transactions
188188
# #after_commit is a good spot to put in a hook to clearing a cache since clearing it from
189189
# within a transaction could trigger the cache to be regenerated before the database is updated.
190190
#
191+
# ==== NOTE: Callbacks are deduplicated per callback by filter.
192+
#
193+
# Trying to define multiple callbacks with the same filter will result in a single callback being run.
194+
#
195+
# For example:
196+
#
197+
# after_commit :do_something
198+
# after_commit :do_something # only the last one will be called
199+
#
200+
# This applies to all variations of <tt>after_*_commit</tt> callbacks as well.
201+
#
202+
# after_commit :do_something
203+
# after_create_commit :do_something
204+
# after_save_commit :do_something
205+
#
206+
# It is recommended to use the +on:+ option to specify when the callback should be run.
207+
#
208+
# after_commit :do_something, on: [:create, :update]
209+
#
210+
# This is equivalent to using +after_create_commit+ and +after_update_commit+, but will not be deduplicated.
211+
#
191212
# === Caveats
192213
#
193214
# If you're on MySQL, then do not use Data Definition Language (DDL) operations in nested

0 commit comments

Comments
 (0)