Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider the Rails 7.1 normalization feature #183

Open
jrochkind opened this issue Jan 19, 2023 · 0 comments
Open

consider the Rails 7.1 normalization feature #183

jrochkind opened this issue Jan 19, 2023 · 0 comments

Comments

@jrochkind
Copy link
Owner

jrochkind commented Jan 19, 2023

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 get out of the way of rails 5.2 ActiveModel::Attributes #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant