diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-02-01 14:20:36 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-02-01 14:20:36 -0800 |
commit | 58410b3d566e6b93c7b71c0eec0fc11ec906b68e (patch) | |
tree | 3f84c6b8bf66468a871263ab7c9b822ad3121b56 | |
parent | 045c77c1bc8f9acdc7efe34ba7af59acfe6f955f (diff) | |
download | rails-58410b3d566e6b93c7b71c0eec0fc11ec906b68e.tar.gz rails-58410b3d566e6b93c7b71c0eec0fc11ec906b68e.tar.bz2 rails-58410b3d566e6b93c7b71c0eec0fc11ec906b68e.zip |
add destroyed records to the currend transaction
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 5 |
2 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 22112fe8ff..af7aef6e43 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -178,6 +178,7 @@ module ActiveRecord def destroy raise ReadOnlyRecord, "#{self.class} is marked as readonly" if readonly? destroy_associations + self.class.connection.add_transaction_record(self) destroy_row if persisted? @destroyed = true freeze diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index 609c395cb6..dd405c7796 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -381,7 +381,10 @@ module ActiveRecord thaw unless restore_state[:frozen?] @new_record = restore_state[:new_record] @destroyed = restore_state[:destroyed] - write_attribute(self.class.primary_key, restore_state[:id]) if self.class.primary_key + pk = self.class.primary_key + if pk && read_attribute(pk) != restore_state[:id] + write_attribute(pk, restore_state[:id]) + end end end end |