DmitryTsepelev / store_model

Work with JSON-backed attributes as ActiveRecord-ish models
MIT License
1.04k stars 85 forks source link

How to have an attribute of type Hash? #178

Closed chernish2 closed 1 month ago

chernish2 commented 1 month ago

Firstly thank you a lot for this great GEM! I have a question. I need to have an attribute of type Hash (just usual Ruby Hash). When I'm making attribute :hash_field, :hash, default: -> { {} } I got an error: ArgumentError: Unknown type :hash My current workaround is to define the type HashType in app/types/hash_type.rb and then register it in config/initializers/types.rb. May be I'm missing something? Is it for real that the Hash type is not supported out of the box?

DmitryTsepelev commented 1 month ago

Hey @chernish2! Unfortunately yes https://api.rubyonrails.org/classes/ActiveModel/Type.html. Maybe that will be a good addition to the Rails codebase 😉