activerecord-typedstore
activerecord-typedstore copied to clipboard
Is there a way to master a nested json with a json column?
For example:
# 'settings' is a json-typed column for the model User in database(pg or mysql)
class User < ApplicationRecord
typed_store :settings do |s|
s.boolean :new_msg, default: true, null: false
s.boolean :some_settings, default: false, null: false
s.array :other_settings, default: [], null: false
end
end
And I want to add some nested json in attributes in the setting column, just like:
{
"new_msg": true,
"some_settings": false,
"other_settings": [
"a",
"b",
"c"
],
"nested_settings": {
"setting_a": true,
"setting_b": false
}
}
Is there any way to make it happen with TypedStore?
loses typing, but the any type will allow you to store nested data if you need to
typed_store :settings do |s|
s.boolean :new_msg, default: true, null: false
s.boolean :some_settings, default: false, null: false
s.string :other_settings, array: true, default: [], null: false
s.any :nested_setting, null: false
end