我正在尝试检索具有 expired_at
的所有记录为零和 expired_at
大于当前时间。
我试过这个:
PriceRule.where("expired_at > ? OR expired_at = ?", DateTime.now, nil)
但这只是返回给我的记录 expired_at
大于 DateTime.now
.为什么是nil
被忽视?
最佳答案
您还可以利用 Rails or
在这里,它将处理 IS NULL
而不是 = NULL
.我还建议使用 Time.current
相反,它对时区有更好的支持。
PriceRule
.where('expired_at > ?', Time.current)
.or(PriceRule.where(expired_at: nil))
关于sql - Rails 中同一列的 OR 条件在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63197704/