ruby-on-rails Rails:在where中使用distinct

mdfafbf1  于 2023-06-07  发布在  Ruby
关注(0)|答案(1)|浏览(184)

我有一个ActiveRecord查询:

Shareholder.where(is_company: false).distinct

这给了我一个错误:
ActiveRecord::StatementInvalid:PG::UndefinedFunction:错误:无法识别json类型的相等运算符
ActiveRecord创建的SQL查询:

SELECT DISTINCT "shareholders".*
FROM "shareholders"
WHERE "shareholders"."deleted" = $1 AND "shareholders"."is_company" = $2

我有点困惑,这是行不通的。怎么了?

ie3xauqp

ie3xauqp1#

Distinct不适用于json列,但您可以尝试这样做

Shareholder.select("DISTINCT ON (shareholders.id) shareholders.*").where(is_company: false).distinct

相关问题