Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "to_key on a destroyed model should return nil". Closes #2440

This reverts commit c544872.
  • Loading branch information...
commit 216d79ef63e3c79a8d45640a8b2d2588be9f1e11 1 parent 8118e41
@spastorino spastorino authored
View
5 activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -3,11 +3,10 @@ module AttributeMethods
module PrimaryKey
extend ActiveSupport::Concern
- # Returns this record's primary key value wrapped in an Array or nil if
- # the record is not persisted? or has just been destroyed.
+ # Returns this record's primary key value wrapped in an Array if one is available
def to_key
key = send(self.class.primary_key)
- persisted? && key ? [key] : nil
+ [key] if key
end
module ClassMethods
View
2  activerecord/test/cases/primary_keys_test.rb
@@ -26,7 +26,7 @@ def test_to_key_with_customized_primary_key
def test_to_key_with_primary_key_after_destroy
topic = Topic.find(1)
topic.destroy
- assert_equal nil, topic.to_key
+ assert_equal [1], topic.to_key
end
def test_integer_key
Please sign in to comment.
Something went wrong with that request. Please try again.