{"id":15473047,"url":"https://github.com/hackvan/objects-has-many-through","last_synced_at":"2025-10-26T17:34:39.837Z","repository":{"id":145341769,"uuid":"140044595","full_name":"hackvan/objects-has-many-through","owner":"hackvan","description":null,"archived":false,"fork":false,"pushed_at":"2018-07-07T02:34:35.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T22:26:00.391Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hackvan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-07T01:56:32.000Z","updated_at":"2018-07-07T02:34:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"e5e8f76b-50f3-4921-88d3-096fb249e0a3","html_url":"https://github.com/hackvan/objects-has-many-through","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"d2c2663560c6c1bb2bd300546397874d35aa15fb"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hackvan/objects-has-many-through","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackvan%2Fobjects-has-many-through","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackvan%2Fobjects-has-many-through/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackvan%2Fobjects-has-many-through/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackvan%2Fobjects-has-many-through/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackvan","download_url":"https://codeload.github.com/hackvan/objects-has-many-through/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackvan%2Fobjects-has-many-through/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261073339,"owners_count":23105639,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T02:42:27.892Z","updated_at":"2025-10-26T17:34:39.749Z","avatar_url":"https://github.com/hackvan.png","language":"Ruby","readme":"# Ruby Object Relations: Has-Many-Through Lab\n\n## Objectives\n\n1. Write classes that are related to each other via the \"has-many-through\" relationship.\n2. Write methods that use the \"has-many-through\" relationship to deliver information on related objects.\n\n## Overview\n\nIn this lab, we'll be dealing with two sets of three classes.\n\nWe 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.\n\nWe also have an `Appointment`, `Doctor` and `Patient` class. Appointments belong to a patient and to 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 doctor's through its appointments.\n\n## Instructions\n\nStart with the `Artist`/`Song`/`Genre` domain.\n\n**The `Artist` model:**\n\n* The `Artist` class needs a class variable `@@all` that begins as an empty array\n* The `Artist` class needs a class method `.all` that lists each artist in the class variable\n* An artist is initialized with a name and is saved in the `@@all` array.\n* The `Artist` class needs an instance method, `#new_song`, that takes in an argument of a name and genre creates a new song. That song should know that it belongs to the artist.\n* The `Artist` class needs an instance method, `#songs`, that iterates through all songs and finds the songs that belong to that artist. Try using `select` to achieve this.\n* The `Artist` class needs an instance method, `#genres` that iterates over that artist's songs and collects the genre of each song.\n\n**The `Song` model:**\n\n* The `Song` class needs a class variable `@@all` that begins as an empty array.\n* The `Song` class needs a class method `.all` that lists each artist in the class variable.\n* A song should be initialized with a name, an artist, and a genre, and be saved in the `@@all` array.\n\n**The `Genre` model:**\n\n* The `Genre` class needs a class variable `@@all` that begins as an empty array.\n* The `Genre` class needs a class method `.all` that lists each artist in the class variable.\n* A genre should be initialized with a name and be saved in the `@@all` array.\n* The `Genre` class needs an instance method, `#new_song`, that takes in an argument of a name and an artist and creates a new song. That song should know that it belongs to the genre.\n* The `Genre` class needs an instance method, `#songs`, that iterates through all songs and finds the songs that belong to that genre.\n* The `Genre` class needs an instance method, `#artists`, that iterates over the genre's collection of songs and collects the artist that owns each song.\n\nNow let's move on to our `Doctor`/`Appointment`/`Patient` domain model.\n\n**The `Doctor` model:**\n\n* The `Doctor` class needs a class variable `@@all` that begins as an empty array.\n* The `Doctor` class needs a class method `.all` that lists each artist in the class variable.\n* A doctor should be initialized with a name and be saved in the `@@all` array.\n* The `Doctor` class needs an instance method, `#new_appointment`, that takes in a date and an instance of the `Patient` class and creates a new appointment. That appointment should know that it belongs to the doctor\n* The `Doctor` class needs an instance method, `#appointments`, that iterates through all appointments and finds those belonging to this doctor.\n* The `Doctor` class needs an instance method, `#patients`, that iterates over that doctor's appointments and collects the patient that belongs to each appointment.\n\n**The `Appointment` model:**\n\n* The `Appointment` class needs a class variable `@@all` that begins as an empty array.\n* The `Appointment` class needs a class method `.all` that lists each artist in the class variable.\n* An appointment should be initialized with a date (as a string, like `\"Monday, August 1st\"`), a patient, and a doctor. The appointment should be saved in the `@@all` array.\n\n**The `Patient` model:**\n\n* The `Patient` class needs a class variable `@@all` that begins as an empty array.\n* The `Patient` class needs a class method `.all` that lists each artist in the class variable.\n* A patient is instantiated with a name and be saved in the `@@all` array.\n* 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.\n* The `Patient` class needs an instance method, `#appointments`, that iterates through the appointments array and returns appointments that belong to the patient.\n* The `Patient` class needs an instance method, `#doctors`, that iterates over that patient's appointments and collects the doctor that belongs to each appointment.\n\n\u003cp data-visibility='hidden'\u003eView \u003ca href='https://learn.co/lessons/ruby-objects-has-many-through-lab' title='Ruby Object Relations: Has-Many-Through Lab'\u003eRuby Object Relations: Has-Many-Through Lab\u003c/a\u003e on Learn.co and start learning to code for free.\u003c/p\u003e\n\n\u003cp class='util--hide'\u003eView \u003ca href='https://learn.co/lessons/ruby-objects-has-many-through-lab'\u003eHas Many Objects Through Lab\u003c/a\u003e on Learn.co and start learning to code for free.\u003c/p\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackvan%2Fobjects-has-many-through","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackvan%2Fobjects-has-many-through","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackvan%2Fobjects-has-many-through/lists"}