Another type of many-to-many association is a rich join between two models. This is useful when the join table needs to include additional information about the relationship. In this case, the table does have an “id” as a primary key and there is a model corresponding to the database join table. Instead of using “has_and_belongs_to_many”, a rich join uses two sets of “has_many/belongs_to”.
- [Voiceover] We've seen how to create simple…many-to-many associations using has_and_belongs_to_many.…In this movie, we're gonna add more complexity…to our join tables.…I call these rich joins.…First, to understand why we need this complexity,…let's go back to the many-to-many diagram…for the beginning of this chapter.…This is a classic many-to-many example.…We have a number of courses,…we have a number of students taking these courses.…There will be a table named courses…and a table named students, and in the simple join,…we would have a join table between them,…which we would call courses_students.…
In the join table will be two foreign keys,…one for the course, and one for the student.…Here's where the simple join falls short, though.…Imagine that we wanna keep track of more information…than just the fact that a student…is participating in a class.…You might wanna keep track of their seat number,…or the date they signed up,…or the date they last attended,…or how many times they've been absent.…That information belongs in this join table,…
- 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.