jrochkind / attr_json

Serialized json-hash-backed ActiveRecord attributes, super smooth

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

consider the Rails 7.1 normalization feature

jrochkind opened this issue · comments

There is a new normalization feature coming in Rails 7.1. rails/rails#43945

In attr_json 2.0, becuase of changes to sync better with ActiveRecord attribuets, i predict it should just work for attr_json attributes in an ActiveRecord::Base. (But we'll want to test it).

This could be useful for say normalizing empty strings (or all whitespace strings) to nil, which attr_json 2.0 will then by default leave out of the json serialization. Great!

(We still might want a feature to say, specify default normalization for attributes of certain types or something?)

But... as far as I can tell, the Rails 7.1 normalization feature is not available in an ActiveModel::Model, only in ActiveRecord models. rails/rails#43945 (comment).

  • Even if it was... it might not Just Work for AttrJson, becuase we're not actually based on ActiveModel::Attributes. See #18. Although in 2.x we might be enough duck-typed that it would work anyway, depends on the implementation.... if Rails normalization were introduced for non-ActiveRecord ActiveModel ... that might be good encouragement to actually move over to ActiveModel::Attributes fully.

But we of course might want normalization in our AttrJson::Model. Should we implement our own look-aike feature? It would not be all that hard, the basic feature is pretty straightforward and based on the Attribute APIs we're already using extensively.