From 58410b3d566e6b93c7b71c0eec0fc11ec906b68e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 1 Feb 2015 14:20:36 -0800 Subject: add destroyed records to the currend transaction --- activerecord/lib/active_record/persistence.rb | 1 + activerecord/lib/active_record/transactions.rb | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') 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 -- cgit v1.2.3