我正在尝试按一组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。
答案 0 :(得分: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 })