diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2014-05-16 10:50:21 -0700 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2014-05-16 10:50:21 -0700 |
commit | 9900703ebf4d2688b2203e9b28d3cc588fac1641 (patch) | |
tree | c5cb4fd67bb5fad7f2e37c291ff5427beafc2376 /activerecord/lib | |
parent | cb85ddc8395b8468fceca43bf54518f5f3f5d2de (diff) | |
parent | 535f299df9b8228c854d3ed0554feeaf1946812f (diff) | |
download | rails-9900703ebf4d2688b2203e9b28d3cc588fac1641.tar.gz rails-9900703ebf4d2688b2203e9b28d3cc588fac1641.tar.bz2 rails-9900703ebf4d2688b2203e9b28d3cc588fac1641.zip |
Merge pull request #15125 from arthurnn/small_refactoring_transaction_clear
Small refactoring on clear_transaction_record_state
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index 17f76b63b3..51bda88be9 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -295,7 +295,7 @@ module ActiveRecord def committed! #:nodoc: run_callbacks :commit if destroyed? || persisted? ensure - @_start_transaction_state.clear + clear_transaction_record_state(true) end # Call the +after_rollback+ callbacks. The +force_restore_state+ argument indicates if the record @@ -328,7 +328,7 @@ module ActiveRecord begin status = yield rescue ActiveRecord::Rollback - @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) - 1 + clear_transaction_record_state status = nil end @@ -353,9 +353,11 @@ module ActiveRecord end # Clear the new record state and id of a record. - def clear_transaction_record_state #:nodoc: + def clear_transaction_record_state(force = false) #:nodoc: @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) - 1 - @_start_transaction_state.clear if @_start_transaction_state[:level] < 1 + if force || @_start_transaction_state[:level] < 1 + @_start_transaction_state.clear + end end # Restore the new record state and id of a record that was previously saved by a call to save_record_state. |