From 4db10bce7b5ca794c4d408de3b8002bf58233bb7 Mon Sep 17 00:00:00 2001 From: pleax Date: Mon, 17 May 2010 01:47:56 +0400 Subject: AR::Base#clone fixed to set dirty bits for cloned object [#2919 state:committed] Signed-off-by: Jeremy Kemper --- activerecord/lib/active_record/base.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 37675d8ab1..18f75af11b 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1463,12 +1463,18 @@ module ActiveRecord #:nodoc: callback(:after_initialize) if respond_to_without_attributes?(:after_initialize) cloned_attributes = other.clone_attributes(:read_attribute_before_type_cast) cloned_attributes.delete(self.class.primary_key) + @attributes = cloned_attributes + + @changed_attributes = {} + attributes_from_column_definition.each do |attr, orig_value| + @changed_attributes[attr] = orig_value if field_changed?(attr, orig_value, @attributes[attr]) + end + clear_aggregation_cache @attributes_cache = {} @new_record = true ensure_proper_type - @changed_attributes = other.changed_attributes.dup if scope = self.class.send(:current_scoped_methods) create_with = scope.scope_for_create -- cgit v1.2.3