我试图搜索一个数组字段,一个哈希数组,如:
[{"name" => "1", "no" => 2}, {"name" => "2", "no" => "3"}]
这是我的疑问:
Trip.mybookings(:passengers, :name, current_user.id)
这就是范围:
scope :mybookings, ->(column, key, value) { where("? = ANY (SELECT unnest(\"#{column}\") -> ?)", value, key) }
但是我收到了这个错误:
PG::UndefinedFunction: ERROR: operator does not exist: text -> unknown
LINE 1: ...ps" WHERE ('1' = ANY (SELECT unnest("passengers") -> 'name')...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT "trips".* FROM "trips" WHERE ('1' = ANY (SELECT unnest("passengers") -> 'name'))
PG::UndefinedFunction: ERROR: operator does not exist: text -> unknown
LINE 1: ...ps" WHERE ('1' = ANY (SELECT unnest("passengers") -> 'name')...
我不知道应该播放哪个属性以及如何执行此操作?事实上,我不知道为什么要这样做?!
有什么想法吗?