Rails:PG :: UndefinedFunction:ERROR:运算符不存在:text - >未知

时间:2016-11-24 11:19:45

标签: ruby-on-rails postgresql ruby-on-rails-4 search casting

我试图搜索一个数组字段,一个哈希数组,如:

[{"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')...

我不知道应该播放哪个属性以及如何执行此操作?事实上,我不知道为什么要这样做?!

有什么想法吗?

0 个答案:

没有答案