我想我可能已经知道答案了,但是我希望可以有替代的解决方案。
我有一个User
模型与has_many
另一个Enrollment
具有字符串数组的模型相关联roles
。
我试图在角色上运行Ransack搜索,例如:
:enrollments_roles_cont 'guest'
无论我使用哪个运算符搜索都会失败:
帐户:
PG::UndefinedFunction: ERROR: operator does not exist: text[] ~~* unknown
LINE 1: ..." IS NULL AND ("enrollments_public_users"."roles" ILIKE '%ma...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
情商:
PG::InvalidTextRepresentation: ERROR: malformed array literal: "manager"
LINE 1: ... IS NULL AND "enrollments_public_users"."roles" = 'manager' ...
^
DETAIL: Array value must start with "{" or dimension information.
我猜这失败了,因为我的“数组”列实际上是一个字符串。有两个问题。
它不是很漂亮,但是可以工作:
在我的Enrollments
模型中:
ransacker :roles do
Arel.sql("array_to_string(roles, ',')")
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句