From the course: Ruby on Rails 6 Essential Training: Models and Associations
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Traversing a rich join association - Ruby on Rails Tutorial
From the course: Ruby on Rails 6 Essential Training: Models and Associations
Traversing a rich join association
- I want to continue our discussion about the ways that we can do many to many relationships by talking about how we traverse rich join associations. First, let me explain why this is a topic we need to discuss. Let's say that we have a has and belongs to many relationship. Like we have with user and department. We can take a user object and we can call user.departments to get back in array of all of the departments that that user has been assigned. But with the rich joint that we just created, we can't do that. We have a rich join between page and users with user assignments in the middle. But page doesn't have a relationship to users. We didn't define anything in the page class to tell it about users. So pages.users won't work. Page.user_assignments will work. We've made that relationship. And then we could go through those page assignments and get back each and every one of the users. But that's a cumbersome…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Work with associations7m 35s
-
(Locked)
Validate presence with belongs_to2m 39s
-
(Locked)
Destroy dependent-related records3m 10s
-
(Locked)
Has and belongs to many relationships10m 3s
-
(Locked)
Rich join associations6m 28s
-
(Locked)
Traversing a rich join association3m 38s
-
(Locked)
Joining tables during queries6m 51s
-
(Locked)
-