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.
One-to-many associations - Ruby on Rails Tutorial
From the course: Ruby on Rails 5 Essential Training
One-to-many associations
- [Host] In the last movie, we saw how to use one-to-one associations. Now let's build on that to understand how to work with one-to-many associations. One-to-many associations are gonna be similar to one-to-one associations, but there are a few main differences that I wanna highlight. First, one-to-many associations are gonna be much more commonly used. In a typical application, you'll rarely use one-to-one, but you'll use one-to-many the most often. Second, because we have one object related to many objects, we're gonna use plural names. That's both gonna be true when we define the association and also when we call the methods on it. We'll see those in a moment. And third, the relationship is going to return an array of objects back to us instead of a single object. And that just makes sense, right? If we're going to have many records associated with it, we're going to have to store those in an array so that it can hold all of those records. You use a one-to-many association when…
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)
Relationship types7m 2s
-
(Locked)
One-to-one associations9m 42s
-
(Locked)
One-to-many associations7m 54s
-
(Locked)
belongs_to presence validation4m 18s
-
(Locked)
Many-to-many associations: Simple9m 58s
-
(Locked)
Many-to-many associations: Rich10m 17s
-
(Locked)
Traverse a rich association5m 24s
-
(Locked)
-
-
-
-
-
-
-
-
-
-