From 8dbf5a4ddb1924b8460b166a29afb1265a1aaeff Mon Sep 17 00:00:00 2001 From: Nikita Afanasenko Date: Wed, 31 Oct 2012 00:14:16 +0400 Subject: Backport #8078: Fix `attributes_before_type_cast` for serialised attributes. Public method attributes_before_type_cast used to return internal AR structure (ActiveRecord::AttributeMethods::Serialization::Attribute), patch fixes this. Now behaves like read_attribute_before_type_cast and returns unserialised values. --- .../lib/active_record/attribute_methods/serialization.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb index 00023b0b6c..cf4c35cf84 100644 --- a/activerecord/lib/active_record/attribute_methods/serialization.rb +++ b/activerecord/lib/active_record/attribute_methods/serialization.rb @@ -97,6 +97,16 @@ module ActiveRecord super end end + + def attributes_before_type_cast + super.dup.tap do |attributes| + self.class.serialized_attributes.each_key do |key| + if attributes.key?(key) + attributes[key] = attributes[key].unserialized_value + end + end + end + end end end end -- cgit v1.2.3