🕵️♀️ Task
where 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 find in that column. The value could be any type of object, but the Class should usually match the type of column you’re searching in.
You can use an Array of as a value and include a list of values that you’d like to find in the column you’re searching in.
LevelUp
0.0% complete
LevelUp
0.0% complete
| id | title | year | duration | description | image | director_id |
|---|---|---|---|---|---|---|
| 41 | Spirited Away | 2001 | 125 | In the middle of her family... | http://ia.media-imdb.com/im... | 30 |
| 42 | Modern Times | 1936 | 87 | The Tramp struggles to live... | http://ia.media-imdb.com/im... | 27 |
| 43 | North by Northwest | 1959 | 136 | A hapless New York advertis... | http://ia.media-imdb.com/im... | 21 |
| 44 | Back to the Future | 1985 | 116 | A teenager is accidentally ... | http://ia.media-imdb.com/im... | 15 |
| 45 | Citizen Kane | 1941 | 119 | Following the death of a pu... | http://ia.media-imdb.com/im... | 31 |
| 46 | The Shining | 1980 | 146 | A family heads to an isolat... | http://ia.media-imdb.com/im... | 28 |
| 47 | Life Is Beautiful | 1997 | 116 | A Jewish man has a wonderfu... | http://ia.media-imdb.com/im... | 32 |
| 48 | The Pianist | 2002 | 150 | A Polish Jewish musician st... | http://ia.media-imdb.com/im... | 33 |
| id | name | dob | bio | image |
|---|
| id | name | dob | bio | image |
|---|---|---|---|---|
| 41 | John Travolta | 1954-02-18 | John Travolta first gained ... | http://ia.media-imdb.com/im... |
| 42 | Samuel L. Jackson | 1948-12-21 | Samuel L. Jackson usually p... | http://ia.media-imdb.com/im... |
| 43 | Tim Roth | 1961-05-14 | Often mistaken for an Ameri... | http://ia.media-imdb.com/im... |
| 297 | Frankie Faison | 1949-06-10 | http://ia.media-imdb.com/im... | |
| 298 | Don Brockett | 1930-01-30 | ||
| 299 | Frank Seals Jr. | |||
| 300 | Stuart Rudin | 1941-12-16 | ||
| 330 | Stephen Baldwin | 1966-05-12 | http://ia.media-imdb.com/im... |
| id | actor_id | movie_id | name |
|---|---|---|---|
| 41 | 36 | 3 | Fanucci (as Gaston Moschin) |
| 42 | 37 | 3 | Rocco Lampone |
| 43 | 38 | 3 | Young Clemenza (as B. Kirby... |
| 44 | 39 | 3 | Genco |
| 45 | 40 | 3 | Young Mama Corleone (as Fra... |
| 46 | 41 | 4 | Vincent Vega |
| 47 | 42 | 4 | Jules Winnfield |
| 48 | 43 | 4 | Pumpkin / Ringo |
Select all records from the users table that have "joe" in the first_name column.
User.all.where({ :first_name => "joe" })
=> #<User::ActiveRecord_Relation:0x00007fa4341e1ee8>
Select all records from the dishes table that have 20 in the price column.
Dish.all.where({ :price => 20, :rating => 5 })
=> #<Dish::ActiveRecord_Relation:0x00007fa4341e1ee8>
Select the records from the cities table that have the values: 13, 25, and 63 in the id column.
City.all.where({ :id => [13, 25, 63]})
=> #<City::ActiveRecord_Relation:0x00007fa4341e1ee8>