Giter VIP home page Giter VIP logo

sql-relations-assessment-assessment-test's Introduction

SQL Assessment

For this assessment, pretend we now we have a totally different website then from object relations section. Please don't base your answers on your ruby work.

Here, we have a different Yelp-style application. We need customers, restaurants, owners, and reviews. How do they link up?

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
  • Customer#reviews
    • returns all of the reviews written by that customer
  • Owner#restaurants
    • returns all restaurants belonging to that owner
  • Restaurant#owner
    • returns the owner of that restaurant
  • Review#customer
    • returns the customer of that review
  • Review#restaurant
    • returns the restaurant of that particular 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.

Write your domain model here:

sql-relations-assessment-assessment-test's People

Contributors

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