From the course: Ruby on Rails 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Many-to-many associations: Simple

Many-to-many associations: Simple - Ruby on Rails Tutorial

From the course: Ruby on Rails 5 Essential Training

Start my 1-month free trial

Many-to-many associations: Simple

- [Teacher] Now that we've learned how to create one-to-many associations, we're ready to move on to learn many-to-many associations. We'll begin by looking at a simple join, and then move on to a more complex join in the next movie. Many-to-many associations are similar to one-to-many associations because they also have an object which has many objects which belong to it. The difference that as a many-to-many, the objects don't belong to it exclusively. For example, a project has_and_belongs_to_many :collaborators. The project can have many collaborators, but the collaborators can also have many projects. It's not like the project owns a collaborator exclusively. They're allowed to work on other projects, too. You have a BlogPost, which has_and_belongs_to_many :categories. If our BlogPost is both in the technology and training categories, it doesn't mean that no other BlogPost can be in the technology and training categories. Technology will have many BlogPosts. Training will have…

Contents