From 47f1c10c8fb7ed9f8999dda5b4a7f42e34afeec6 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Tue, 10 Jun 2014 08:42:47 -0600 Subject: Keep the types of virtual columns after yaml serialization On MySQL and PostgreSQL, the adapter does not type cast virtual columns for us. --- activerecord/lib/active_record/type/serialized.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord/lib/active_record/type/serialized.rb') diff --git a/activerecord/lib/active_record/type/serialized.rb b/activerecord/lib/active_record/type/serialized.rb index 9144028576..e6d84eadc0 100644 --- a/activerecord/lib/active_record/type/serialized.rb +++ b/activerecord/lib/active_record/type/serialized.rb @@ -36,6 +36,17 @@ module ActiveRecord ActiveRecord::Store::IndifferentHashAccessor end + def init_with(coder) + @subtype = coder['subtype'] + @coder = coder['coder'] + __setobj__(@subtype) + end + + def encode_with(coder) + coder['subtype'] = @subtype + coder['coder'] = @coder + end + private def is_default_value?(value) -- cgit v1.2.3