0

我试图通过一组 id 进行选择,但前提是该shown列为真。我试过了: Product.find(@product_ids, conditions: "shown = true")

但是,这给了我错误:Couldn't find all Products with IDs (2, 3) [WHERE (shown = true)] (found 0 results, but was looking for 2)

在这种特殊情况下,选择的两个产品都shown设置为 false。

4

1 回答 1

4

您可以使用where.

Product.where("id in (?) and shown = ?", @product_ids, true)

或者

Product.where(id: @product_ids, shown: true)

或者

Product.where("id in (:product_ids) and shown = :shown", { product_ids: @product_ids, shown: true })
于 2013-08-30T01:44:42.427 回答