diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-06 09:43:09 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-07 07:03:42 -0600 |
commit | 2dca1ba039eb0d1adad089134749a5093b481666 (patch) | |
tree | 7ffd41b412443ed83fc9ea112fe196b48d0b8490 /activerecord/lib/active_record/attribute_methods | |
parent | ecd4151aa829214c7b10f24bc5eca194089b4319 (diff) | |
download | rails-2dca1ba039eb0d1adad089134749a5093b481666.tar.gz rails-2dca1ba039eb0d1adad089134749a5093b481666.tar.bz2 rails-2dca1ba039eb0d1adad089134749a5093b481666.zip |
Don't query the database schema when calling `serialize`
We need to decorate the types lazily. This is extracted to a separate
API, as there are other refactorings that will be able to make use of
it, and to allow unit testing the finer points more granularly.
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/serialization.rb | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb index 148fc9eae5..60debb7d18 100644 --- a/activerecord/lib/active_record/attribute_methods/serialization.rb +++ b/activerecord/lib/active_record/attribute_methods/serialization.rb @@ -58,11 +58,9 @@ module ActiveRecord Coders::YAMLColumn.new(class_name_or_coder) end - type = columns_hash[attr_name.to_s].cast_type - if type.serialized? - type = type.subtype + decorate_attribute_type(attr_name, :serialize) do |type| + Type::Serialized.new(type, coder) end - property attr_name, Type::Serialized.new(type, coder) # merge new serialized attribute and create new hash to ensure that each class in inheritance hierarchy # has its own hash of own serialized attributes |