小编shu*_*riu的帖子

将postgres hstore sql转换为Arel

hstoreusers表中列了一个列properties.

如何将where条件中的静态sql字符串转换为aRel语法?

User.where("properties -> 'is_robber' = 'true'") #=> ...some users
Run Code Online (Sandbox Code Playgroud)

我试过了:

ut = User.arel_table
condition = ut["properties -> 'is_robber'"].eq('true')
User.where(condition) #=> throws pg error
Run Code Online (Sandbox Code Playgroud)

这会产生错误的sql:

 SELECT "users".* FROM "users" WHERE "users"."properties -> 'is_robber'" = 'true'
Run Code Online (Sandbox Code Playgroud)

与我需要的相比:

SELECT "users".* FROM "users" WHERE "users".properties -> 'is_robber' = 'true'
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails arel hstore

3
推荐指数
1
解决办法
1132
查看次数

标签 统计

arel ×1

hstore ×1

ruby-on-rails ×1