如何在Rails查询中找到nil的对立面

时间:2012-04-21 00:34:48

标签: ruby-on-rails activerecord mongoid

很高兴地使用MongoidActiveRecord这样:

Task.where(project_id: params[:project_id], archived_at: nil)
# find me the tasks for project_id that haven't been archived

但说出相反的说法有什么直接的方式呢?

# find me the tasks for project_id that have been archived
# i.e. where archived_at is not nil

无法找出或找出第一行代码的反转。 我认为它应该是直截了当的:)

1 个答案:

答案 0 :(得分:2)

我想你想用这个:

:archived_at.ne => nil 

请看这里:MongoId-Matchers-NE