You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/relations.md
+8-4
Original file line number
Diff line number
Diff line change
@@ -219,8 +219,8 @@ A one-to-many relationship that is linked through an intermediate model. This me
219
219
220
220
Consider an application where::
221
221
222
-
- A *Country* has many *Users*.
223
-
- A *User* has many *Posts*.
222
+
- A **Country** has many **Users**.
223
+
- A **User** has many **Posts**.
224
224
225
225
You want to fetch all Posts for a Country, even though the Posts table does not directly reference the Country.
226
226
@@ -257,11 +257,15 @@ A `belongsToMany` relationship is used for many-to-many associations between two
257
257
258
258
Consider an application where:
259
259
260
-
-*Students* can enroll in multiple *Courses*.
261
-
- A *Course* can have multiple *Students*.
260
+
-**Students** can enroll in multiple **Courses**.
261
+
- A **Course** can have multiple **Students**.
262
262
263
263
Since both Students and Courses can be related to each other in many ways, we use a pivot table to manage this association.
264
264
265
+
The pivot table should have a name derived from the name of both tables. In this example, it would be `course_student` - note the singular form of the words. The order of the words is alphabetical.
266
+
267
+
The table should contain a primary key (`id` - auto_increment) and two foreign keys for both of models: `course_id` and `student_id`.
0 commit comments