🕵️♀️ Task
You can negate criteria with where.not
. Like where
, where.not
is used for filtering a collection of records down using various criteria. Most commonly, we pass a Hash
argument. The key is the column you’re searching in and the value is what you’re trying to exclude from the results.
LevelUp
0.0% complete
LevelUp
0.0% complete
id | title | year | duration | description | image | director_id |
---|---|---|---|---|---|---|
9 | The Lord of the Rings: The ... | 2003 | 201 | Gandalf and Aragorn lead th... | http://ia.media-imdb.com/im... | 8 |
10 | Fight Club | 1999 | 139 | An insomniac office worker ... | http://ia.media-imdb.com/im... | 9 |
11 | Star Wars: Episode V - The ... | 1980 | 124 | After the rebels have been ... | http://ia.media-imdb.com/im... | 10 |
12 | The Lord of the Rings: The ... | 2001 | 178 | A meek hobbit of The Shire ... | http://ia.media-imdb.com/im... | 8 |
13 | One Flew Over the Cuckoo's ... | 1975 | 133 | Upon admittance to a mental... | http://ia.media-imdb.com/im... | 11 |
14 | Inception | 2010 | 148 | A skilled extractor is offe... | http://ia.media-imdb.com/im... | 5 |
15 | Goodfellas | 1990 | 146 | Henry Hill and his friends ... | http://ia.media-imdb.com/im... | 12 |
16 | Star Wars: Episode IV - A N... | 1977 | 121 | Luke Skywalker joins forces... | http://ia.media-imdb.com/im... | 13 |
id | name | dob | bio | image |
---|---|---|---|---|
9 | David Fincher | 1962-08-28 | David Fincher was born in 1... | http://ia.media-imdb.com/im... |
10 | Irvin Kershner | 1923-04-29 | Irvin Kershner was born on ... | http://ia.media-imdb.com/im... |
11 | Milos Forman | 1932-02-18 | Because his parents died in... | http://ia.media-imdb.com/im... |
12 | Martin Scorsese | 1942-11-17 | Martin Scorsese was born on... | http://ia.media-imdb.com/im... |
13 | George Lucas | 1944-05-14 | George Walton Lucas, Jr. wa... | http://ia.media-imdb.com/im... |
14 | Akira Kurosawa | 1910-03-23 | After training as a painter... | http://ia.media-imdb.com/im... |
15 | Robert Zemeckis | 1951-05-14 | A "whizkid" with special ef... | http://ia.media-imdb.com/im... |
16 | Lilly Wachowski | 1967-12-29 | Director, writer and produc... | http://ia.media-imdb.com/im... |
id | name | dob | bio | image |
---|---|---|---|---|
9 | Jeffrey DeMunn | 1947-04-25 | Jeffrey DeMunn was born on ... | http://ia.media-imdb.com/im... |
10 | Larry Brandenburg | 1948-05-03 | http://ia.media-imdb.com/im... | |
11 | Neil Giuntoli | 1959-12-20 | http://ia.media-imdb.com/im... | |
12 | Brian Libby | http://ia.media-imdb.com/im... | ||
13 | David Proval | 1942-05-20 | David Proval launched his a... | http://ia.media-imdb.com/im... |
14 | Joseph Ragno | 1936-03-11 | http://ia.media-imdb.com/im... | |
15 | Jude Ciccolella | http://ia.media-imdb.com/im... | ||
16 | Marlon Brando | 1924-04-03 | Marlon Brando is widely con... | http://ia.media-imdb.com/im... |
id | actor_id | movie_id | name |
---|---|---|---|
9 | 9 | 1 | 1946 D.A. |
10 | 10 | 1 | Skeet |
11 | 11 | 1 | Jigger |
12 | 12 | 1 | Floyd |
13 | 13 | 1 | Snooze |
14 | 14 | 1 | Ernie |
15 | 15 | 1 | Guard Mert |
16 | 16 | 2 | Don Vito Corleone |
Select all records from the users table that _don't_ have "joe" in the first_name column.
User.all.where.not({ :first_name => "joe" })
=> #<User::ActiveRecord_Relation:0x00007fa4341e1ee8>
Select all records from the dishes table that _don't_ have 20 in the price column.
Dish.all.where.not({ :price => 20 })
=> #<Dish::ActiveRecord_Relation:0x00007fa4341e1ee8>