diff options
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 13 | ||||
-rw-r--r-- | railties/lib/rails/tasks/restart.rake | 2 |
3 files changed, 7 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 7c076864a3..a6176dffdb 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -96,7 +96,8 @@ module ActiveRecord # Returns true if the record is persisted, i.e. it's not a new record and it was # not destroyed, otherwise returns false. def persisted? - !(new_record? || destroyed?) + sync_with_transaction_state + !(@new_record || @destroyed) end # Saves the model. diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index b620233c3a..91ea81f2d2 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -469,18 +469,13 @@ module ActiveRecord # method recursively goes through the parent of the TransactionState and # checks if the ActiveRecord object reflects the state of the object. def sync_with_transaction_state - update_attributes_from_transaction_state(@transaction_state, 0) + update_attributes_from_transaction_state(@transaction_state) end - def update_attributes_from_transaction_state(transaction_state, depth) - @reflects_state = [false] if depth == 0 - + def update_attributes_from_transaction_state(transaction_state) if transaction_state && transaction_state.finalized? && !has_transactional_callbacks? - unless @reflects_state[depth] - restore_transaction_record_state if transaction_state.rolledback? - clear_transaction_record_state - @reflects_state[depth] = true - end + restore_transaction_record_state if transaction_state.rolledback? + clear_transaction_record_state end end end diff --git a/railties/lib/rails/tasks/restart.rake b/railties/lib/rails/tasks/restart.rake index 1af0302824..1e8940b675 100644 --- a/railties/lib/rails/tasks/restart.rake +++ b/railties/lib/rails/tasks/restart.rake @@ -1,4 +1,4 @@ desc "Restart app by touching tmp/restart.txt" -task restart: :environment do +task :restart do FileUtils.touch('tmp/restart.txt') end |