@@ -188,6 +188,16 @@ module Transactions
188
188
# #after_commit is a good spot to put in a hook to clearing a cache since clearing it from
189
189
# within a transaction could trigger the cache to be regenerated before the database is updated.
190
190
#
191
+ # *Warning*: Callbacks are deduplicated according to the callback and method.
192
+ # This means you cannot have multiple <tt>after_xxx_commit</tt> shortcuts calling the same method.
193
+ #
194
+ # after_create_commit :do_foo #This will NOT fire
195
+ # after_save_commit :do_foo
196
+ #
197
+ # Instead, use after_commit directly
198
+ #
199
+ # after_commit :do_foo, on: [:create, :save]
200
+ #
191
201
# === Caveats
192
202
#
193
203
# If you're on MySQL, then do not use Data Definition Language (DDL) operations in nested
@@ -237,24 +247,32 @@ def after_commit(*args, &block)
237
247
end
238
248
239
249
# Shortcut for <tt>after_commit :hook, on: [ :create, :update ]</tt>.
250
+ #
251
+ # *Warning*: only one <tt>after_xxx_commit</tt> shortcut can call any given method
240
252
def after_save_commit ( *args , &block )
241
253
set_options_for_callbacks! ( args , on : [ :create , :update ] , **prepend_option )
242
254
set_callback ( :commit , :after , *args , &block )
243
255
end
244
256
245
257
# Shortcut for <tt>after_commit :hook, on: :create</tt>.
258
+ #
259
+ # *Warning*: only one <tt>after_xxx_commit</tt> shortcut can call any given method
246
260
def after_create_commit ( *args , &block )
247
261
set_options_for_callbacks! ( args , on : :create , **prepend_option )
248
262
set_callback ( :commit , :after , *args , &block )
249
263
end
250
264
251
265
# Shortcut for <tt>after_commit :hook, on: :update</tt>.
266
+ #
267
+ # *Warning*: only one <tt>after_xxx_commit</tt> shortcut can call any given method
252
268
def after_update_commit ( *args , &block )
253
269
set_options_for_callbacks! ( args , on : :update , **prepend_option )
254
270
set_callback ( :commit , :after , *args , &block )
255
271
end
256
272
257
273
# Shortcut for <tt>after_commit :hook, on: :destroy</tt>.
274
+ #
275
+ # *Warning*: only one <tt>after_xxx_commit</tt> shortcut can call any given method
258
276
def after_destroy_commit ( *args , &block )
259
277
set_options_for_callbacks! ( args , on : :destroy , **prepend_option )
260
278
set_callback ( :commit , :after , *args , &block )
0 commit comments