aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods/primary_key.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods/primary_key.rb')
-rw-r--r--activerecord/lib/active_record/attribute_methods/primary_key.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb
index 5f06452247..8bd898d126 100644
--- a/activerecord/lib/active_record/attribute_methods/primary_key.rb
+++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -7,7 +7,7 @@ module ActiveRecord
# 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
@@ -48,7 +48,7 @@ module ActiveRecord
end
attr_accessor :original_primary_key
-
+
# Attribute writer for the primary key column
def primary_key=(value)
@quoted_primary_key = nil