DmitryTsepelev / store_model

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

How to have an attribute of type Hash? #178

Closed chernish2 closed 3 months ago

chernish2 commented 4 months 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 3 months ago

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