我hstore在users表中列了一个列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)