Please sign in to comment.
JSON is still an adapter specific type.
Several changes were made in #21110 which I am strongly opposed to. (this is what I get for going on vacation. ) No type should be introduced into the generic `ActiveRecord::Type` namespace, and *certainly* should not be registered into the registry unconstrained unless it is supported by *all* adapters (which basically means that it was specified in the ANSI SQL standard). I do not think `# :nodoc:` ing the type is sufficient, as it still makes the code of Rails itself very unclear as to what the role of that class is. While I would argue that this shouldn't even be a super class, and that MySql and PG's JSON types are only superficially duplicated (they might look the same but will change for different reasons in the future). However, I don't feel strongly enough about it as a point of contention (and the biggest cost of harming the blameability has already occured), so I simply moved the superclass into a namespace where its role is absolutely clear. After this change, `attribute :foo, :json` will once again work with MySQL and PG, but not with Sqlite3 or any third party adapters. Unresolved questions -------------------- The types that and adapter publishes (at least those are unique to that adapter, and not adding additional behavior like `MysqlString` should probably be part of the adapter's public API. Should we standardize the namespace for these, and document them?
- Loading branch information...
Showing with 50 additions and 36 deletions.
- +1 −1 activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
- +1 −0 activerecord/lib/active_record/connection_adapters/postgresql/oid.rb
- +10 −0 activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb
- +1 −1 activerecord/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb
- +2 −1 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
- +2 −2 activerecord/lib/active_record/type.rb
- +33 −0 activerecord/lib/active_record/type/internal/abstract_json.rb
- +0 −31 activerecord/lib/active_record/type/json.rb
|@@ -0,0 +1,10 @@|
|module OID # :nodoc:|
|class Json < Type::Internal::AbstractJson|
|@@ -0,0 +1,33 @@|
|module Internal # :nodoc:|
|class AbstractJson < Type::Value # :nodoc:|
|::ActiveSupport::JSON.decode(value) rescue nil|
|if value.is_a?(::Array) || value.is_a?(::Hash)|