【问题标题】:How to find opposite of nil in Rails queries如何在 Rails 查询中找到 nil 的对立面
【发布时间】:2012-04-21 00:34:47
【问题描述】:

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

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

【问题讨论】:

    标签: ruby-on-rails activerecord mongoid


    【解决方案1】:

    我想你想用这个:

    :archived_at.ne => nil 
    

    看这里:MongoId-Matchers-NE

    【讨论】:

      猜你喜欢
      • 2014-11-19
      • 1970-01-01
      • 2017-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多