我有一个带有expired_at日期字段的Product模型.我想查询返回所有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,...
解决方法
manufactured_at = Date.tomorrow Product.where("expired_at > ? OR expired_at IS NULL",manufactured_at)
试试这个