Closed kg-currenxie closed 2 years ago
Hello @kg-currenxie,
jsonb_accessor
doesn't do any automatic conversion of values.
jsonb_accessor :settings, albums_permission: [:integer, default: 0]
simply creates an attribute albums_permission
that defaults to 0
and tries to cast the value to an integer. I guess it would somehow be possible to make jsonb_accessor
work nicely with Rails' enum
but honestly I think this is quite the niche use case. But you are welcome to contribute to this repository and give it go.
Understood :) I'll switch to storing the string in the db instead
Hi.
Normal AR model + enum:
Test
Actual value in database column is the integer
With jsonb_accessor
Test
Actual value in the database is
{"albums_permission": "public"}
rather than{"albums_permission": 1}
Shouldn't the
[:integer, default: 0]
convert the enum string to integer before saving? 🤔 am i doing something wrong? or maybe is this expected behavior?