Welcome to Netflix! For this domain, we'll be modeling out movies, genres, and reviews.
- Domain modelling
- has_many / belongs_to relationships
- SQL
Select
statements - SQL Joins
-
As a first step, please write out the domain model in this file
- What we are concerned about is which tables have foreign keys
- Don't stress: There may be multiple correct answers based on your conception of the problem.
Eg. for our books and authors your deliverable would look like
id | title | author_id
id | name |
-
As a second step, please fill in the stubbed out methods in the respective model. The important thing here is to know what SQL will fire to select the data you're looking for. For example, if I want a method called 'author' for my
Book
class, it might look something like this.
class Book
include Databaseable::InstanceMethods # Access to our database
extend Databaseable::ClassMethods
ATTRIBUTES = {
id: "INTEGER PRIMARY KEY",
title: "TEXT",
release_year: "INTEGER"
}
attr_accessor(*self.public_attributes)
attr_reader :id
def author
sql = <<-SQL
SELECT * FROM authors
WHERE id = ?
SQL
self.class.db.execute(sql, self.author_id)
end
end
- Genre#movies
- returns all of the movies with that given genre
- Movie.by_year(year)
- given a year, find all of the movies that were released in that year
- Movie#genres
- returns all of the genres for that given movie
- Movie#reviews
- returns all the reviews for a given movie
- Review#movie
- returns the movie for a given review
- The data always lives on the belongs_to relationship
- Do the belongs_to first, then do the has_many
- If there is a many to many, we need a third table
- We've provided you with a
console.rb
file and aseeds.rb
file. You can runruby tools/seeds.rb
to add some data to your database, and thenruby tools/console.rb
to interact with your Ruby classes.