activerecord 3.2.13查询使用的地方不是nil

时间:2017-02-05 23:55:33

标签: ruby-on-rails ruby activerecord

我知道有更新版本的activerecord有Model.where.not。旧版本的activerecord是否有解决方法?

我想做Model.where.not(:completed_at => nil)

之类的事情

其中completed_at是时间戳值。

1 个答案:

答案 0 :(得分:3)

你可以使用arel,但它有点冗长

Model.where(Model.arel_table[:completed_at].not_eq(nil))

否则转到原始SQL

Model.where('completed_at IS NOT NULL')