Associations II
Lesson 1 of 1
  1. 1
    So far we’ve made an app that stores data using two models. We used the has_many / belongs_to association to model a one-to-many relationship between the data. But not all data is one-to-many. For…
  2. 2
    Looking at the request/response cycle, we need four parts to the build the movie app: models, controllers, routes, and views. Let’s begin by creating the models.
  3. 3
    What did we just do? Check out the diagram in the browser: 1. We created three models - Movie, Actor, and Part. 2. In the models, we used the has_many :through association to connect the Movie mod…
  4. 4
    Nice work! Let’s review what we did: 1. We added columns to the movies table and actors table 2. We used the t.belongs_to methods in the parts table to add foreign keys, setting up the many-to-man…
  5. 5
    Well done! The movies show up on the page. Let’s add another action to display a specific movie and its actors. Looking at the [seven standard controller actions](https://www.codecademy.com/articl…
  6. 6
    Great job! The app displays all actors that belong to a movie. The has_many :through association lets us easily query for all actors that belong to a movie.
  7. 7
    Congratulations! You build a movie website that lets people browse a movie’s cast and an actor’s filmography. What can we generalize so far? * Actors and movies can be modeled using a _many-to-many…

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory