ruby - select single property in hstore field with Rails 4.1 -
i using postgres 9.3 rails 4.1.
suppose have table properties hstore colum.
i want select single key within hstore column in scope (or somewhere else..)
what tried: model.select("properties -> 'category'")
what happens: rails gives me array this:
[#<model id: nil>, #<model id: nil>, #<model id: nil>, #<model id: nil>] what want:
[#<model id: nil, category: 'foo'>, #<model id: nil, category: 'bar'>, #<model id: nil, category: 'baz'>, #<model id: nil, category: 'foo'>]
try:
=> model.where("properties @> hstore(?, ?)", 'key', 'value').select(:category) => [#<model id: nil, category: 'foo'>] ruby-on-rails ruby postgresql ruby-on-rails-4 hstore
No comments:
Post a Comment