aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-06-07 10:23:25 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-07 10:23:25 -0600
commit35164093f5005c4312674bf3e00e2a92e2e3c7e5 (patch)
tree743bc5f769f8fcd73d160a32b0632b50f2667a38
parent287e926d564bbe8db6baad85d35276042e0dc47a (diff)
downloadrails-35164093f5005c4312674bf3e00e2a92e2e3c7e5.tar.gz
rails-35164093f5005c4312674bf3e00e2a92e2e3c7e5.tar.bz2
rails-35164093f5005c4312674bf3e00e2a92e2e3c7e5.zip
Remove dead branch when restoring ID within a transaction
There is no way to have an instance of an Active Record model where `has_attribute?(self.class.primary_key)` returns false. The record is always initialized in such a way that `@raw_attributes` will have an id key with nil for the value.
-rw-r--r--activerecord/lib/active_record/transactions.rb9
1 files changed, 2 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb
index d733063f5a..08ef38be8c 100644
--- a/activerecord/lib/active_record/transactions.rb
+++ b/activerecord/lib/active_record/transactions.rb
@@ -339,7 +339,7 @@ module ActiveRecord
# Save the new record state and id of a record so it can be restored later if a transaction fails.
def remember_transaction_record_state #:nodoc:
- @_start_transaction_state[:id] = id if has_attribute?(self.class.primary_key)
+ @_start_transaction_state[:id] = id
unless @_start_transaction_state.include?(:new_record)
@_start_transaction_state[:new_record] = @new_record
end
@@ -371,12 +371,7 @@ module ActiveRecord
@raw_attributes = @raw_attributes.dup if @raw_attributes.frozen?
@new_record = restore_state[:new_record]
@destroyed = restore_state[:destroyed]
- if restore_state.has_key?(:id)
- write_attribute(self.class.primary_key, restore_state[:id])
- else
- @raw_attributes.delete(self.class.primary_key)
- @attributes.delete(self.class.primary_key)
- end
+ write_attribute(self.class.primary_key, restore_state[:id])
@raw_attributes.freeze if was_frozen
end
end