You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, store_model isn't persisted in DB, unless I change an attribute explicitly.
What is the correct way to store default attributes in the DB?
I have the following model:
class User < ApplicationRecord
attribute :email_settings, Subscriptions.to_type
scope :weekly_subscribed, -> { where('email_settings @> ?', { weekly: true }.to_json) }
end
class Subscriptions
include StoreModel::Model
attribute :weekly, :boolean, default: true
end
When a new user is created, the email_settings value in the DB is {}.
But I want to query all users using jsonb query, as following: User.weekly_subscribed
puts User.weekly_subscribed.count
# 0
Because the JSONB doesn't have a default value in the DB.
Gem: 0.12.0
Ruby: 2.7.4
Rails: 5.2.5
The text was updated successfully, but these errors were encountered:
By default, store_model isn't persisted in DB, unless I change an attribute explicitly.
What is the correct way to store default attributes in the DB?
I have the following model:
When a new user is created, the
email_settings
value in the DB is{}
.But I want to query all users using
jsonb
query, as following:User.weekly_subscribed
Because the JSONB doesn't have a default value in the DB.
Gem: 0.12.0
Ruby: 2.7.4
Rails: 5.2.5
The text was updated successfully, but these errors were encountered: