From the course: Ruby on Rails Models and Associations
Unlock the full course today
Join today to access over 24,200 courses taught by industry experts.
Overview of associations - Ruby on Rails Tutorial
From the course: Ruby on Rails Models and Associations
Overview of associations
- [Instructor] In this chapter, we'll work with active record associations beginning with an overview. Associations keep our application's data well organized so that it can be used efficiently. Relational databases have three main association types one to one, one to many, and many to many. One to one associations relate one record to exactly one other record. An example would be one classroom that has one and only one teacher assigned to it. We would say a classroom has one teacher and a teacher belongs to a classroom. To make this work in the database, you'd put a column on the teacher's table to hold a foreign key, probably something like classroom ID. In a one to one association, which of these tables holds the foreign key is a design choice. They could be reversed. With that relationship established, if you have a classroom record and you want to find out what teacher belongs to it, you take its ID and search…
Contents
-
-
-
-
-
-
(Locked)
Overview of associations3m 57s
-
(Locked)
Create a one-to-many association2m 19s
-
(Locked)
Use a one-to-many association4m 53s
-
(Locked)
Destroy dependent related records4m 34s
-
(Locked)
Has and belongs to many associations5m 52s
-
(Locked)
Rich join associations5m 56s
-
(Locked)
Traverse a rich join association4m 17s
-
(Locked)
Join tables during queries5m 57s
-
(Locked)
-