我有以下发现不工作查找记录,其中和“不等于”
self.participants.where(:role => "Celebrant", :created_at => year..Time.now, :board_id => !current_board.id)
我想找到满足上述和
:board_id not equal to current_board.id
参加什么我怎样才能做到这一点与轨道3在哪里?
我有以下发现不工作查找记录,其中和“不等于”
self.participants.where(:role => "Celebrant", :created_at => year..Time.now, :board_id => !current_board.id)
我想找到满足上述和
:board_id not equal to current_board.id
参加什么我怎样才能做到这一点与轨道3在哪里?
你想要的东西是这样的:
self.participants.
where(:role => "Celebrant", :created_at => year..Time.now).
where('board_id <> ?', current_board.id)
你必须下降到字符串条件和SQL代码段为“不等于”为Hash conditions are a bit limited:
只有平等,范围和子集哈希条件可以检查。
哇,我不知道你可以链接在哪里发言。这很好。 – chell
@chell:查询方法可以链接和混合,并根据需要进行链接和匹配;他们很懒,并且不会直接向数据库进行交谈,直到您通过询问某些数据来强制他们。 –
您也可以使用Metawhere gem,位于http://erniemiller.org/projects/metawhere/ – eugen
我通常使用像“AND ID NOT IN(?)”这样的sql,将“?id”的集合传递给“? “ – socjopata