Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

to_key on a destroyed model should return nil

  • Loading branch information...
commit c5448721b5054b8a467958d60427fdee15eac604 1 parent bc364af
@spastorino spastorino authored
View
2  activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -7,7 +7,7 @@ module PrimaryKey
# the record is not persisted? or has just been destroyed.
def to_key
key = send(self.class.primary_key)
- [key] if key
+ persisted? && key ? [key] : nil
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 [1], topic.to_key
+ assert_equal nil, topic.to_key
end
def test_integer_key
Please sign in to comment.
Something went wrong with that request. Please try again.