我有一个具有属性 skip_reason
的 Order
模型。我想列出除full
和locked
以外的所有具有skip_reason
的顺序。我正在使用where.not
,但它不会在skip_reason
列上返回具有nil
的订单。
我想到了以下条件,
> orders.pluck(:skip_reason)
=> ["locked", nil, nil, "unavailable", nil, nil, "locked", nil, nil, "full"]
> orders.where.not(skip_reason: ["full", "locked"]).pluck(:skip_reason)
=> ["unavailable"]
那么,如何列出skip_reason
列中具有nil
值的订单?任何建议都将不胜感激。
在Rails 4中尝试了此操作,并且似乎可以使用。对你还可以吗?否则,我认为您应该使用RAW SQL作为WHERE子句
orders.where(skip_reason: [nil, "unavailable"])