使用Rails 3查找记录,其中“不等于”

时间:2011-09-13 08:54:54

标签: ruby-on-rails-3 find

我有以下找不到的发现

self.participants.where(:role => "Celebrant", :created_at => year..Time.now, :board_id => !current_board.id)  

我想找到满足上述要求的参与者

:board_id not equal to current_board.id

如何使用rails 3在哪里?

1 个答案:

答案 0 :(得分:8)

你想要这样的东西:

self.participants.
     where(:role => "Celebrant", :created_at => year..Time.now).
     where('board_id <> ?', current_board.id)  

您必须将“不等于”的字符串条件和SQL片段下拉为Hash conditions are a bit limited

  

只有使用哈希条件才能进行相等,范围和子集检查。

相关问题