Giter Site home page Giter Site logo

ruby-objects-has-many-through-lab-nyc-web-career-042219's Introduction

Ruby Object Relations: Has-Many-Through Lab

Objectives

  1. Write classes that are related to each other via the "has-many-through" relationship.
  2. Write methods that use the "has-many-through" relationship to deliver information on related objects.

Overview

In this lab, we'll be dealing with two sets of three classes.

We have a Song, Artist and Genre class. Songs belong to an artist and belong to a genre. A genre has many songs and an artist has many songs. An artist has many genres through its songs and a genre has many artists through its songs.

We also have an Appointment, Doctor and Patient class. Appointments belong to a Patient and a Doctor. A Doctor has many Appointments and a Patient has many Appointments. A Doctor has many Patients through its Appointments and a Patient has many Doctors through its Appointments.

Instructions

Start with the Artist/Song/Genre domain.

The Artist model:

The Song model:

The Genre model:

Now let's move on to our Doctor/Appointment/Patient domain model.

The Doctor model:

  • The Doctor class needs an instance method, #new_appointment, that takes in a an instance of the Patient class and a date, and creates a new Appointment. That Appointment should know that it belongs to the doctor
  • The Doctor class needs an instance method, #appointments, that iterates through all Appointments and finds those belonging to this doctor.
  • The Doctor class needs an instance method, #patients, that iterates over that doctor's Appointments and collects the patient that belongs to each Appointments.

The Appointment model:

The Patient model:

  • The Patient class needs an instance method, #new_appointment, that takes in an argument of a doctor and a date and creates a new Appointment. The Appointment should know that it belongs to the patient.
  • The Patient class needs an instance method, #appointments, that iterates through the Appointments array and returns Appointments that belong to the patient.
  • The Patient class needs an instance method, #doctors, that iterates over that patient's Appointments and collects the doctor that belongs to each Appointment.

View Has Many Objects Through Lab on Learn.co and start learning to code for free.

ruby-objects-has-many-through-lab-nyc-web-career-042219's People

Contributors

annjohn avatar aviflombaum avatar danielseehausen avatar drakeltheryuujin avatar ga-be avatar geluso avatar jmburges avatar kkterai avatar maxwellbenton avatar pletcher avatar qunli02 avatar sgharms avatar sophiedebenedetto avatar telegraham 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.