aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-02-07 23:23:18 +0000
committerJon Leighton <j@jonathanleighton.com>2012-02-07 23:36:22 +0000
commit75ffd8701d04d943eddcafee08e19b90bce8936c (patch)
tree01120f523de4bf4037e2b9be3587d53e9a5bd5a0 /activerecord/lib
parent4b8fe5961ec97e5e36ea4510e7fd47847ec9a57f (diff)
downloadrails-75ffd8701d04d943eddcafee08e19b90bce8936c.tar.gz
rails-75ffd8701d04d943eddcafee08e19b90bce8936c.tar.bz2
rails-75ffd8701d04d943eddcafee08e19b90bce8936c.zip
Fix attribute_before_type_cast for serialized attributes. Fixes #4837.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/attribute_methods/serialization.rb8
-rw-r--r--activerecord/lib/active_record/core.rb2
2 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb
index 0c8e4e4b9a..7efef73472 100644
--- a/activerecord/lib/active_record/attribute_methods/serialization.rb
+++ b/activerecord/lib/active_record/attribute_methods/serialization.rb
@@ -88,6 +88,14 @@ module ActiveRecord
super
end
end
+
+ def read_attribute_before_type_cast(attr_name)
+ if serialized_attributes.include?(attr_name)
+ super.unserialized_value
+ else
+ super
+ end
+ end
end
end
end
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index a2ce620354..e87fba550b 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -209,6 +209,8 @@ module ActiveRecord
# The dup method does not preserve the timestamps (created|updated)_(at|on).
def initialize_dup(other)
cloned_attributes = other.clone_attributes(:read_attribute_before_type_cast)
+ self.class.initialize_attributes(cloned_attributes)
+
cloned_attributes.delete(self.class.primary_key)
@attributes = cloned_attributes