Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3: How to get all Posts which ids are not in a given list?

To get all posts with publisher_id equals to 10, 16, or 17, I do:

Post.where(:publisher_id => [10, 16, 17])

How would I get all posts with publisher_id not equals to 10, 16, or 17 (i.e. all possible ids besides those three) ?

like image 877
Misha Moroshko Avatar asked May 20 '11 04:05

Misha Moroshko


1 Answers

Just perform a :

Post.where(["publisher_id NOT IN (?)", [10, 16, 17]])
like image 87
ronnieonrails Avatar answered Jan 04 '23 06:01

ronnieonrails