I am building a Rails 5.2 app. I am using Postgres. In this app I have a User object and in this object i got a JSONB column.
I need to be able to query specific attributes within the JSONB object.
This is how I define it in the User model:
serialize :preferences
store_accessor :preferences, PREFERENCES
This is the content of the object:
{"digest_is_active"=>true, "digest_frequency"=>"modal", "digest_time"=>"10:00"}
I tried this:
scope :digest_active, -> { where("preferences @> ?", { "digest_is_active": true }.to_json) }
User.where("preferences->>'digest_time' = ?", "10:00")
The query seems to run without errors but cannot find the User object.
SELECT "users".* FROM "users" WHERE (preferences @> '{"digest_is_active":true}') LIMIT $1 [["LIMIT", 11]]