diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-05-31 06:01:59 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-01 17:52:46 -0600 |
commit | e08494a912c89b1eb444c5c358e9aa880b2e4c66 (patch) | |
tree | e61c768fa2fc42e612c17b2fb19e758d062a454d /activerecord/lib/active_record | |
parent | 87cc918daab39174c82b0aeb617fb8e4b4f107fb (diff) | |
download | rails-e08494a912c89b1eb444c5c358e9aa880b2e4c66.tar.gz rails-e08494a912c89b1eb444c5c358e9aa880b2e4c66.tar.bz2 rails-e08494a912c89b1eb444c5c358e9aa880b2e4c66.zip |
New records should remain new after yaml serialization
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/core.rb | 3 | ||||
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 6 |
2 files changed, 7 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 205cae9b2a..88c1fc7e4c 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -284,7 +284,7 @@ module ActiveRecord init_internals - @new_record = false + @new_record = coder['new_record'] self.class.define_attribute_methods @@ -354,6 +354,7 @@ module ActiveRecord # coder # => {"attributes" => {"id" => nil, ... }} def encode_with(coder) coder['attributes'] = @raw_attributes + coder['new_record'] = new_record? end # Returns true if +comparison_object+ is the same exact object, or +comparison_object+ diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 78ae05073a..2e3bcc0956 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -49,7 +49,11 @@ module ActiveRecord def instantiate(attributes, column_types = {}) klass = discriminate_class_for_record(attributes) column_types = klass.decorate_columns(column_types.dup) - klass.allocate.init_with('attributes' => attributes, 'column_types' => column_types) + klass.allocate.init_with( + 'attributes' => attributes, + 'column_types' => column_types, + 'new_record' => false, + ) end private |