我想为我的 Rails 应用程序(v 3.2.6)使用 Squeel gem(基于 Arel)。我的 hstore 列称为属性。
这些工作非常好:
User.where{(firstname == 'Ryan') & (lastname == 'Bates')}
User.where{"properties @> ('male' => '1')"}
第二个例子是一个普通的 Postgres 查询,因为 Squeel 似乎不支持 hstore 函数。
这些不起作用:
User.where{"properties @> ('male' => '1')" & firstname == 'Ryan'}
User.where{("properties @> ('male' => '1')") & (firstname == 'Ryan')}
错误:
NoMethodError: undefined method `&' for "properties @> ('male' => '1')":String
我确实理解错误,但我不知道如何封装我的 hstore 查询。有没有更好的方法来使用 Squeel 或 Arel 构建 hstore 查询?