diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-08-14 17:40:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-14 17:40:13 -0400 |
commit | efad56a0d93c51d7ebce5007a80df522335430bd (patch) | |
tree | df314458c113bad4ca2e0a8ae3a9caffd36324c0 /activerecord/lib | |
parent | 509dfdca98cf82244c33deae66baf7175279400c (diff) | |
parent | c847e17300f4cacfcabf79bea746700697ce57ff (diff) | |
download | rails-efad56a0d93c51d7ebce5007a80df522335430bd.tar.gz rails-efad56a0d93c51d7ebce5007a80df522335430bd.tar.bz2 rails-efad56a0d93c51d7ebce5007a80df522335430bd.zip |
Merge pull request #30229 from kamipo/allow_serialize_with_custom_coder
Allow `serialize` with a custom coder on `json` and `array` columns
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/serialization.rb | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/serialization.rb b/activerecord/lib/active_record/attribute_methods/serialization.rb index acd47629dd..ebc2baed34 100644 --- a/activerecord/lib/active_record/attribute_methods/serialization.rb +++ b/activerecord/lib/active_record/attribute_methods/serialization.rb @@ -70,7 +70,7 @@ module ActiveRecord end decorate_attribute_type(attr_name, :serialize) do |type| - if type_incompatible_with_serialize?(type) + if type_incompatible_with_serialize?(type, class_name_or_coder) raise ColumnNotSerializableError.new(attr_name, type) end @@ -80,12 +80,9 @@ module ActiveRecord private - def type_incompatible_with_serialize?(type) - type.is_a?(ActiveRecord::Type::Json) || - ( - defined?(ActiveRecord::ConnectionAdapters::PostgreSQL) && - type.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array) - ) + def type_incompatible_with_serialize?(type, class_name) + type.is_a?(ActiveRecord::Type::Json) && class_name == ::JSON || + type.respond_to?(:type_cast_array, true) && class_name == ::Array end end end |