Git Product home page Git Product logo

phase-4-active-record-associations-review-lab's Introduction

Active Record Associations Review Lab

Learning Goals

  • Create one-to-many and many-to-many associations
  • Use has_many, belongs_to and has_many :through Active Record macros

Instructions

Flatiron School has started its own taxi service, FlatironX, and we need to start developing the application's domain model!

Three basic models have already been created, Passenger, Ride, and Taxi.

Your job is set up a has_many :through relationship between these three models so that we can keep track of who's driving who around. It will work like this:

Taxi -< Rides >- Passengers

This way, a taxi can have many passengers, and a passenger can have many taxis!

Deliverables

Updating the Database with Migrations

Each table only has a primary key, so you'll need to add the foreign keys to the appropriate model so that Active Record can handle the "has_many :through" relationship.

You can either edit the migration files directly and add the foreign keys, or generate a new migration with rails g migration to add columns to the appropriate table.

Once your migrations are done, run rails db:migrate to run the migrations.

Adding Active Record Macros

After completing the migrations, you'll also need to update the Taxi, Passenger, and Ride models with the appropriate Active Record macros.

The tests expect to be able to call certain instance methods on each of these models, such as passenger.taxis, so make sure to add the appropriate has_many and belongs_to macros to your models.

Check out the join table section in the Active Record Association Rails Guide if you need a refresher on these.

Resources

phase-4-active-record-associations-review-lab's People

Contributors

ihollander avatar lizbur10 avatar

Stargazers

 avatar  avatar

Watchers

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