Coder Social home page Coder Social logo

sql-practice-relations-challenge-atx01-seng-ft-042020's Introduction

SQL Assessment

Welcome to Netflix! For this domain, we'll be modeling out movies, genres, and reviews.

Topics / Objectives

  • Domain modelling
  • has_many / belongs_to relationships
  • SQL Select statements
  • SQL Joins

Deliverables

  1. 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

    books

    id | title | author_id

    author

    id | name |

  2. 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

Hints:

  • 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 a seeds.rb file. You can run ruby tools/seeds.rb to add some data to your database, and then ruby tools/console.rb to interact with your Ruby classes.

sql-practice-relations-challenge-atx01-seng-ft-042020's People

Contributors

ipc103 avatar maxwellbenton avatar notnotdrew avatar

Watchers

 avatar Mohawk Greene avatar Victoria Thevenot avatar Bernard Mordan avatar Otha avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar  avatar  avatar Ben Oren avatar Matt avatar Antoin avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Dominique De León avatar  avatar Lisa Jiang avatar Vicki Aubin avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.