Last active
August 31, 2020 10:28
-
-
Save frahugo/8ceb262e929d4c0a9575 to your computer and use it in GitHub Desktop.
Ransack with JSONB query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Registration < ActiveRecord::Base | |
scope :nhb_consent_eq, -> (enum = "yes") { | |
where("document @> ?", { nhb_consent: { value: enum } }.to_json ) | |
} | |
private | |
def self.ransackable_scopes(auth_object = nil) | |
%i(nhb_consent_eq) | |
end | |
end | |
> Registration.search(nhb_consent_eq: "yes").result.to_sql | |
SELECT "registrations".* FROM "registrations" WHERE (document @> '{"nhb_consent":{"value":"yes"}}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment