我的Product
模型带有expired_at
日期字段。我想查询返回所有expired_at
值大于某个值或等于nil的产品。
但我遇到了麻烦:
manufactured_at = Date.tomorrow
Product.where('expired_at > ? OR expired_at = NULL', manufactured_at)
# => ActiveRecord::Relation []
Product.all
# => Product id: 1, expired_at: nil, Product id; 2, expired_at: nil, ...
如何在查询中获取这些产品?
答案 0 :(得分:11)
manufactured_at = Date.tomorrow
Product.where("expired_at > ? OR expired_at IS NULL", manufactured_at)
试试这个