3

愉快地使用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

无法弄清楚或找出第一行代码的倒数。我认为它应该很简单:)

4

1 回答 1

2

我想你想用这个:

:archived_at.ne => nil 

看看这里:MongoId-Matchers-NE

于 2012-04-21T00:48:12.863 回答