diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-10 11:47:25 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-06-10 11:47:25 -0300 |
commit | 4bd2a50f882065ab4113df4c5711dd1a156a465b (patch) | |
tree | 1494aae135529e4724b2f18e8bf300e9e043895a /activerecord/lib | |
parent | d5f480c5324c02d89b23e24a92a7a4ea58de59bc (diff) | |
parent | 47f1c10c8fb7ed9f8999dda5b4a7f42e34afeec6 (diff) | |
download | rails-4bd2a50f882065ab4113df4c5711dd1a156a465b.tar.gz rails-4bd2a50f882065ab4113df4c5711dd1a156a465b.tar.bz2 rails-4bd2a50f882065ab4113df4c5711dd1a156a465b.zip |
Merge pull request #15609 from sgrif/sg-yaml-virtual-columns
Keep the types of virtual columns after yaml serialization
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/column.rb | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/core.rb | 1 | ||||
-rw-r--r-- | activerecord/lib/active_record/type/serialized.rb | 11 |
3 files changed, 18 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index 72c6990ba5..21273364b9 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -13,7 +13,7 @@ module ActiveRecord ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(\.\d+)?\z/ end - attr_reader :name, :cast_type, :null, :sql_type, :default_function + attr_reader :name, :cast_type, :sql_type, :default_function delegate :type, :precision, :scale, :limit, :klass, :accessor, :text?, :number?, :binary?, :serialized?, :changed?, @@ -34,7 +34,7 @@ module ActiveRecord @name = name @cast_type = cast_type @sql_type = sql_type - @null = null + @nullable = null @original_default = default @default_function = nil end @@ -61,6 +61,10 @@ module ActiveRecord clone.instance_variable_set('@cast_type', type) end end + + def null + @nullable + end end class NullColumn < Column diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 79388f53b5..7edaf256c7 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -356,6 +356,7 @@ module ActiveRecord def encode_with(coder) coder['raw_attributes'] = @raw_attributes coder['attributes'] = @attributes + coder['column_types'] = @column_types_override coder['new_record'] = new_record? end 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) |