开发者

find records using Rails 3 where and 'not equal'

I have the following find which does not work

self.participan开发者_Go百科ts.where(:role => "Celebrant", :created_at => year..Time.now, :board_id => !current_board.id)  

What I want to to find the participants that satisfy the above and

:board_id not equal to current_board.id

How can I do this with rails 3 where?


You'd want something like this:

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

You have to drop down to string conditions and SQL snippets for "not equals" as Hash conditions are a bit limited:

Only equality, range and subset checking are possible with Hash conditions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜