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/associations/basics.md
+8-8
Original file line number
Diff line number
Diff line change
@@ -5,17 +5,17 @@ title: Basics
5
5
6
6
# Association Basics
7
7
8
-
Sequelize provides what are called __associations__.
9
-
These can be declared on your models to define common [__relationships__](https://en.wikipedia.org/wiki/Cardinality_(data_modeling)) between your tables.
8
+
Sequelize provides what are called **associations**.
9
+
These can be declared on your models to define common [**relationships**](<https://en.wikipedia.org/wiki/Cardinality_(data_modeling)>) between your tables.
10
10
11
-
The two concepts are closely related, but not the same. __Associations__ are defined in JavaScript between your _models_, while
12
-
__relationships__ are defined in your database between your _tables_.
11
+
The two concepts are closely related, but not the same. **Associations** are defined in JavaScript between your _models_, while
12
+
**relationships** are defined in your database between your _tables_.
13
13
14
14
Sequelize supports the standard associations: [One-To-One](https://en.wikipedia.org/wiki/One-to-one_%28data_model%29), [One-To-Many](https://en.wikipedia.org/wiki/One-to-many_%28data_model%29) and [Many-To-Many](https://en.wikipedia.org/wiki/Many-to-many_%28data_model%29).
15
15
16
16
## One-to-one Relationships
17
17
18
-
In a One-To-One relationship, a row of one table is associated with a single row of another table.
18
+
In a One-To-One relationship, a row of one table is associated with a single row of another table.
19
19
20
20
The most common type of One-To-One relationship is one where one side is mandatory, and the other side is optional.
21
21
For instance, a driving license always belongs to a single person, but a person can have zero or one driving licenses <small>(from the same place)</small>.
@@ -25,7 +25,7 @@ erDiagram
25
25
people ||--o| driving_licenses : drivingLicense
26
26
```
27
27
28
-
One-To-One relationships can be created by using __the[`HasOne`](./has-one.md)association__.
28
+
One-To-One relationships can be created by using **the[`HasOne`](./has-one.md)association**.
29
29
30
30
## One-to-many Relationships
31
31
@@ -38,7 +38,7 @@ erDiagram
38
38
people ||--o{ cities : birthplace
39
39
```
40
40
41
-
One-To-Many relationships can be created by using __the[`HasMany`](./has-many.md)association__.
41
+
One-To-Many relationships can be created by using **the[`HasMany`](./has-many.md)association**.
42
42
43
43
## Many-to-many Relationships
44
44
@@ -51,4 +51,4 @@ erDiagram
51
51
people }o--o{ toots : likedToots
52
52
```
53
53
54
-
Many-To-Many relationships can be created by using __the[`BelongsToMany`](./belongs-to-many.md)association__.
54
+
Many-To-Many relationships can be created by using **the[`BelongsToMany`](./belongs-to-many.md)association**.
Copy file name to clipboardExpand all lines: docs/associations/belongs-to-many.md
+32-19
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ title: BelongsToMany
5
5
6
6
# The BelongsToMany Association
7
7
8
-
The BelongsToMany association is used to create a [Many-To-Many relationship](https://en.wikipedia.org/wiki/Many-to-many_(data_model)) between two models.
8
+
The BelongsToMany association is used to create a [Many-To-Many relationship](<https://en.wikipedia.org/wiki/Many-to-many_(data_model)>) between two models.
9
9
10
10
In a Many-To-Many relationship, a row of one table is associated with _zero, one or more_ rows of another table, and vice versa.
11
11
@@ -16,7 +16,7 @@ erDiagram
16
16
people }o--o{ toots : likedToots
17
17
```
18
18
19
-
Because foreign keys can only point to a single row, Many-To-Many relationships are implemented using a junction table (called __through table__ in Sequelize), and are
19
+
Because foreign keys can only point to a single row, Many-To-Many relationships are implemented using a junction table (called **through table** in Sequelize), and are
20
20
really just two One-To-Many relationships.
21
21
22
22
```mermaid
@@ -54,7 +54,7 @@ and will receive the two foreign keys: `userId` and `tootId`.
54
54
55
55
:::caution String `through` option
56
56
57
-
The `through` option is used to specify the through __model__, not the through __table__.
57
+
The `through` option is used to specify the through **model**, not the through **table**.
58
58
We recommend that you follow the same naming conventions as other models (i.e. PascalCase & singular):
59
59
60
60
```ts
@@ -72,11 +72,17 @@ class Person extends Model<InferAttributes<Person>, InferCreationAttributes<Pers
72
72
73
73
## Customizing the Junction Table
74
74
75
-
The junction table can be customized by creating the model yourself, and passing it to the `through` option.
75
+
The junction table can be customized by creating the model yourself, and passing it to the `through` option.
76
76
This is useful if you want to add additional attributes to the junction table.
@@ -462,8 +473,7 @@ In the example above, we did not need to specify the `postId` attribute. This is
462
473
If you use TypeScript, you need to let TypeScript know that the foreign key is not required. You can do so using the second generic argument of the `BelongsToManyCreateAssociationMixin` type.
0 commit comments