Learn to work with many-to-many associations in Rails. Many to many associations are used when an object has other objects which belong to it, but not to it exclusively. Because of this, these associations need to use a join table to keep track of which objects have relationships to other objects. In Rails we define both sides using “has_and_belongs_to_many”. In a simple many-to-many association, the join table does not include an “id” as a primary key and there is no model corresponding to the database join table.
- [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 many BlogPosts.…And several BlogPosts can make…
- Creating and configuring a new Ruby on Rails project
- Generating controllers and views
- Handling server requests
- Using different types of routes
- Rendering and viewing templates
- Generating migrations and models
- Creating, updating, and deleting records
- Finding records with queries
- Understanding relationship types
- Writing controllers for CRUD
- Working with layouts and helpers
- Managing application assets
- Building forms
- Validating data
- Authenticating users
Skill Level Beginner
1. What Is Ruby on Rails?
2. Get Started
3. Controllers, Views, and Dynamic Content
4. Databases and Migrations
5. Models and ActiveRecord
7. CRUD, REST, and Resourceful Routes
8. Controllers and CRUD
9. Layouts, Partials, and View Helpers
12. Data Validation
13. Controller Features
14. User Authentication
15. Improve the Simple CMS
Next steps1m 44s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.