asi*_*niy 7 ruby activerecord ruby-on-rails
我有一个Product带expired_at日期字段的模型.我想要查询返回所有产品的expired_at价值大于某个值或等于零.
但我遇到了麻烦:
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, ...
Run Code Online (Sandbox Code Playgroud)
如何在查询中获取这些产品?
Vru*_*war 12
manufactured_at = Date.tomorrow
Product.where("expired_at > ? OR expired_at IS NULL", manufactured_at)
Run Code Online (Sandbox Code Playgroud)
试试这个
| 归档时间: |
|
| 查看次数: |
4273 次 |
| 最近记录: |