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

时间:2022-02-10 12:13:00

Happily using Mongoid and ActiveRecord like this:

愉快地使用Mongoid和ActiveRecord如下:

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

But what's a straightforward way for saying the opposite?

但是,用什么直接的方式来表达相反的意思呢?

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

Can't figure out or find out the inverse of the first line of code. I assume it should be straightforward :)

无法求出或求出第一行代码的倒数。我想应该很简单:

1 个解决方案

#1


2  

I think you want to use this:

我想你想用这个:

:archived_at.ne => nil 

Take a look at here: MongoId-Matchers-NE

请看这里:MongoId-Matchers-NE。

#1


2  

I think you want to use this:

我想你想用这个:

:archived_at.ne => nil 

Take a look at here: MongoId-Matchers-NE

请看这里:MongoId-Matchers-NE。