You can write a scope for this.
I'm in the process of creating some additional scopes ontop of Surus specifically for hstore arrays.: https://github.com/jackc/surus
This gem helped me on the way, it already provides you with the scopes to work on regular hstores.
specifically for hstore arrays.
Doing this kind of work on hstore arrays can be quite tricky,
Basically we would want to unnest the array, cast this back to hstore, and then use the hstore operand @> to check if right hand key=>value pair exists within left hand subselect. The only way to achieve this is with a subquery.
Review.where(" exists ( SELECT * FROM ( SELECT hstore(unnest(reviews.answers))) x(item) WHERE x.item @> '"qid" => "299"')");
This should work nicely.
CHeck out my fork, https://github.com/milankubin/surus It will provide you with two scopes for now:
Model.hstore_array_has_any(column, value) # will look for anything matching value inside array
Model.hstore_array_has_pairs(column, hash) # the answer you are looking for :)
=> #<ActiveRecord::Relation []>
2.1.2 :002 > Lead.hstore_array_has_pairs(:m3_data, {"name" => "3-zitsbank"})
Lead Load (2.0ms) SELECT "leads".* FROM "leads" WHERE ( exists ( SELECT * FROM ( SELECT hstore(unnest("m3_data"))) x(item) WHERE x.item @> '"name"=>"3-zitsbank"'))
=> #<ActiveRecord::Relation [#<Lead id: 35655,[.......]
It's not true that hstore does not support indexes. You can index on individual keys and even when nested within a hstore array. It's not easy though, and will require you to write your own index planner when adding the index.
Take a look at this answer, this might get you started:
PostgreSQL - query against GIN index of HSTORE value
I haven't ventured into this world yet, but It's certainly possible.