diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2019-04-02 16:36:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-02 16:36:07 -0700 |
commit | 59bed68d5e37b994f5e607c3d2b8c5424a0948b9 (patch) | |
tree | c1ff0b535dd314d2d509056a4d70ae0ff34c205a /activerecord/lib | |
parent | 798f175c65bbfd95b3fa0dd639ca08ae8485d5d1 (diff) | |
download | rails-59bed68d5e37b994f5e607c3d2b8c5424a0948b9.tar.gz rails-59bed68d5e37b994f5e607c3d2b8c5424a0948b9.tar.bz2 rails-59bed68d5e37b994f5e607c3d2b8c5424a0948b9.zip |
Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`. (#35804)
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index fe3842b905..a45d228298 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -234,6 +234,12 @@ module ActiveRecord set_callback(:commit, :after, *args, &block) end + # Shortcut for <tt>after_commit :hook, on: [ :create, :update ]</tt>. + def after_save_commit(*args, &block) + set_options_for_callbacks!(args, on: [ :create, :update ]) + set_callback(:commit, :after, *args, &block) + end + # Shortcut for <tt>after_commit :hook, on: :create</tt>. def after_create_commit(*args, &block) set_options_for_callbacks!(args, on: :create) |