🕵️‍♀️ Task

Select all records from the movies table that have been directer by Christopher Nolan.

movies

  • id (integer)
  • title (string)
  • year (integer)
  • duration (integer)
  • description (text)
  • image (string)
  • director_id (integer)

directors

  • id (integer)
  • name (string)
  • dob (date)
  • bio (text)
  • image (string)

actors

  • id (integer)
  • name (string)
  • dob (date)
  • bio (text)
  • image (string)

characters

  • id (integer)
  • actor_id (integer)
  • movie_id (integer)
  • name (string)
📖Method

where is used for filtering a collection of records down using various criteria. You can pass an Array argument. The first element in the Array must be a String that contains a SQL fragment. The criteria that is being searched for is replaced with ?. Each additional Array element will be inserted into the SQL fragment in the order they appear.

If the criteria for the search comes from a User, this is one way Rails can prevent SQL injection attacks.


Returns a new relation, which is the result of filtering the current relation according to the conditions in the arguments. where accepts conditions in one of several formats.

Given a String argument, the String is passed to the query constructor as an SQL fragment, and used in the where clause of the query.

Note that building your own string from user input may expose your application to injection attacks if not done properly. As an alternative, it is recommended to use one of the following methods…

class Movie < ActiveRecord::Base end
class Director < ActiveRecord::Base end
class Actor < ActiveRecord::Base end
class Character < ActiveRecord::Base end