diff options
author | Stefan Budeanu <stefan.budeanu@shopify.com> | 2016-12-01 17:39:15 -0500 |
---|---|---|
committer | Stefan Budeanu <stefan.budeanu@shopify.com> | 2016-12-09 11:14:37 -0500 |
commit | 371c083fb0620efebf7bd0188a66486403e12ecc (patch) | |
tree | 4c10587ae04edb22e00e4c0a8d1ba2024786057d /activerecord/lib/active_record/transactions.rb | |
parent | 872faa958398fa5aaf6b0e4cd6a8090503d6885a (diff) | |
download | rails-371c083fb0620efebf7bd0188a66486403e12ecc.tar.gz rails-371c083fb0620efebf7bd0188a66486403e12ecc.tar.bz2 rails-371c083fb0620efebf7bd0188a66486403e12ecc.zip |
Emulate db trigger behaviour for after_commit :destroy, :update
Race conditions can occur when an ActiveRecord is destroyed
twice or destroyed and updated. The callbacks should only be
triggered once, similar to a SQL database trigger.
Diffstat (limited to 'activerecord/lib/active_record/transactions.rb')
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index af3fc88282..ce939c8b97 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -461,9 +461,10 @@ module ActiveRecord when :create transaction_record_state(:new_record) when :destroy - destroyed? + defined?(@_trigger_destroy_callback) && @_trigger_destroy_callback when :update - !(transaction_record_state(:new_record) || destroyed?) + !(transaction_record_state(:new_record) || destroyed?) && + (defined?(@_trigger_update_callback) && @_trigger_update_callback) end end end |