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.
Work with associations - Ruby on Rails Tutorial
From the course: Ruby on Rails 6 Essential Training: Models and Associations
Work with associations
- [Narrator] In this chapter, we're going to learn about Active Record Associations. Much of the power of Ruby on Rails lies in creating good associations to keep our data well organized, so that it can be used efficiently. There are three main association types. And this is not just for Ruby on Rails, it's for all relational databases. You can have a one-to-one, a one-to-many, or a many-to-many association. Let's take a look at each one of these. First, one-to-one associations. Those are often abbreviated as 1:1, and that's when you have one object that's related to one and only one other object. So for example, we might have a classroom and a teacher. The classroom has one and only one teacher assigned to it, and the teacher belongs to the classroom. To make this work in the database, you would have a classrooms table and you'd have a teacher's table, and you would put a foreign key on the teacher's table. So that…
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)
-