ruby - Rails hStore postgresql activerecord database query? -
i want able query hstore column on pg database , return values corresponding specific key.
the data looks this: (keep in mind :data
postgresql hstore
)
[ id: 2, data: {"tags"=>"ruby, objects", "type"=>"video", "title"=>"rubytapas: blocks, procs, , lambdas"}, id: 3, data: {"tags"=>"javascript, objects", "type"=>"video", "title"=>"rubytapas: blocks, procs, , lambdas"} ]
i want effect of this:
model.uniq.pluck(:tags)
and output expect is:
ruby, objects, javascript
*i strictly trying implement activerecord , postgresql.
i able desired result doing:
model.pluck(:data).map{|j| j['tags'].split(',') }.flatten.uniq
i still interested in solution doesn't require map
on activerecord relation. please advise.
Comments
Post a Comment