Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With hstore_accessor is it possible to pluck an hstore field? #74

Open
axelson opened this issue Feb 3, 2017 · 0 comments
Open

With hstore_accessor is it possible to pluck an hstore field? #74

axelson opened this issue Feb 3, 2017 · 0 comments

Comments

@axelson
Copy link

axelson commented Feb 3, 2017

Say I have a User model with an hstore field called settings that contains a boolean called notifications_enabled. That allows me to do

[34] pry(main)> User.last.notifications_enabled
=> true

But if I didn't want to load the User model into an instance is there a way to utilize hstore_accessor to pluck out just the reminders_enabled value? I can currently do something like:

[35] pry(main)> User.where(id: 1).pluck("settings->'notifications_enabled'")
=> ["true"]

But that is less than ideal because we lose the translation of the string "true" to the value true and I'd rather not hardcode the Postgres "settings->'notifications_enabled'" query.

Ideally we could do something like:

User.where(id: 1).pluck(:notifications_enabled)
=> [true]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant