aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-07-02 07:00:26 -0600
committerSean Griffin <sean@thoughtbot.com>2014-07-02 07:00:26 -0600
commitb6e15f9a1111469ac1c41eee23fa6ab3f2ec5be3 (patch)
treee79bbe4411c271f95ad8612550ebd4bd43b19794 /activerecord/lib/active_record
parent5c87b5c5248154cf8aa76cce9a24a88769de022d (diff)
downloadrails-b6e15f9a1111469ac1c41eee23fa6ab3f2ec5be3.tar.gz
rails-b6e15f9a1111469ac1c41eee23fa6ab3f2ec5be3.tar.bz2
rails-b6e15f9a1111469ac1c41eee23fa6ab3f2ec5be3.zip
Don't error when `dup`ing a record with no PK
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/attribute_set.rb6
-rw-r--r--activerecord/lib/active_record/core.rb3
2 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb
index 8a964fb03c..df4fd31e08 100644
--- a/activerecord/lib/active_record/attribute_set.rb
+++ b/activerecord/lib/active_record/attribute_set.rb
@@ -52,6 +52,12 @@ module ActiveRecord
super
end
+ def reset(key)
+ if include?(key)
+ write_from_database(key, nil)
+ end
+ end
+
protected
attr_reader :attributes
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 224112b559..30b8485c8b 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -315,9 +315,8 @@ module ActiveRecord
##
def initialize_dup(other) # :nodoc:
- pk = self.class.primary_key
@attributes = @attributes.dup
- @attributes.write_from_database(pk, nil)
+ @attributes.reset(self.class.primary_key)
run_callbacks(:initialize) unless _initialize_callbacks.empty?