我有一个付款状态字符串字段的订单模型。通常这个领域应该填充,但有时它是零。我有以下范围使用where.not与Rails时混淆结果
scope :not_pending, -> { where.not(payment_status: 'pending') }
在我的一个测试中,payment_status为零,但我仍然得到一个空的范围结果。如果我改变它来删除.not,我会再次得到一个空的结果,所以我有点困惑。
编辑 - 添加SQL
"SELECT "orders".* FROM "orders" INNER JOIN "order_compilations" ON "orders"."id" = "order_compilations"."order_id" WHERE "order_compilations"."menu_group_id" = 3724 AND ("orders"."payment_status" != 'pending')"
看到生成的SQL语句,并在您的测试数据库运行它们 – emaillenin