无法在非对象上调用 jsonb_each - rails 更新后查询中断

cannot call jsonb_each on a non-object - query broke after rails update

所以我在 postgres 上有以下 rails 查询,当我 运行 rails 4

时工作正常
@products = @products.offset(offset).limit(@limit).where(status: "visible").where("add_to_inventory =? OR (add_to_inventory =? AND inventory !=? )", false, true, "{}").where.not("ARRAY(select distinct (jsonb_each(inventory)).value->>'quantity' as integer)='{0}'")

现在我最近更新到最新的稳定版 rails 5,现在每次评估时我都会收到以下错误:

PG::InvalidParameterValue: ERROR: cannot call jsonb_each on a non-object : SELECT DISTINCT "products"."priority" AS alias_0, "products"."id" AS alias_1, "products"."id" FROM "products" INNER JOIN "categories" ON "categories"."deleted" =  AND "categories"."id" = "products"."category_id" LEFT OUTER JOIN "product_translations" ON "product_translations"."product_id" = "products"."id" WHERE "products"."deleted" =  AND (categories.company_id =1) AND "products"."status" IN (, ) AND "products"."category_id" IN (, , , , , , , ) AND "products"."status" =  AND (add_to_inventory =FALSE OR (add_to_inventory =TRUE AND inventory !='{}' )) AND NOT (ARRAY(select distinct (jsonb_each(inventory)).value->>'quantity' as integer)='{0}') ORDER BY "products"."priority" ASC, "products"."id" ASC LIMIT  OFFSET 

导致此问题的可能更改有哪些以及如何解决?谢谢

在 Rails 5 他们改变了这个,你必须使用 default: {} 而不是 default: '{}' 来进行 jsob b 迁移。

工作查询:

@products = @products.offset(offset).limit(@limit).where(status: "visible").where("add_to_inventory =? OR (add_to_inventory =? AND inventory !=? )", false, true, {}).where.not("ARRAY(select distinct (jsonb_each(inventory)).value->>'quantity' as integer)='{0}'")