我有一個付款狀態字符串字段的訂單模型。通常這個領域應該填充,但有時它是零。我有以下範圍使用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