Skip to content

Commit 85f3204

Browse files
authored
fix wrong code in polymorphic-associations.md (#780)
1 parent c31f9d1 commit 85f3204

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

docs/associations/polymorphic-associations.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ abstract class AbstractComment<Attributes, CreationAttributes> extends Model<
3434
> {
3535
declare id: number;
3636

37-
@Attributes(DataTypes.STRING)
37+
@Attribute(DataTypes.STRING)
3838
@NotNull
3939
declare content: string;
4040

41-
@Attributes(DataTypes.INTEGER)
41+
@Attribute(DataTypes.INTEGER)
4242
@NotNull
4343
declare targetId: number;
4444
}
@@ -72,17 +72,17 @@ This solution only requires a single table, to which we add multiple, mutually-e
7272
class Comment extends Model<InferAttributes<Comment>, InferCreationAttributes<Comment>> {
7373
declare id: number;
7474

75-
@Attributes(DataTypes.STRING)
75+
@Attribute(DataTypes.STRING)
7676
@NotNull
7777
declare content: string;
7878

79-
@Attributes(DataTypes.INTEGER)
79+
@Attribute(DataTypes.INTEGER)
8080
declare articleId: number | null;
8181

8282
@BelongsTo(() => Article, 'articleId')
8383
declare article?: Article;
8484

85-
@Attributes(DataTypes.INTEGER)
85+
@Attribute(DataTypes.INTEGER)
8686
declare videoId: number | null;
8787

8888
@BelongsTo(() => Video, 'videoId')
@@ -111,23 +111,23 @@ In this type of polymorphic association, we don't use foreign keys at all.
111111
Instead, we use two columns: one to store the type of the associated model, and one to store the ID of the associated model.
112112

113113
As stated above, we must disable the foreign key constraints on the association, as the same column is referencing multiple tables.
114-
This can be done by using the `constraints: false`.
114+
This can be done by using the `foreignKeyConstraints: false`.
115115

116116
We then use [association scopes](./association-scopes.md) to filter which comments belong to which models.
117117

118118
```ts
119119
class Comment extends Model<InferAttributes<Comment>, InferCreationAttributes<Comment>> {
120120
declare id: number;
121121

122-
@Attributes(DataTypes.STRING)
122+
@Attribute(DataTypes.STRING)
123123
@NotNull
124124
declare content: string;
125125

126-
@Attributes(DataTypes.STRING)
126+
@Attribute(DataTypes.STRING)
127127
@NotNull
128128
declare targetModel: 'article' | 'video';
129129

130-
@Attributes(DataTypes.INTEGER)
130+
@Attribute(DataTypes.INTEGER)
131131
@NotNull
132132
declare targetId: number;
133133

@@ -156,7 +156,7 @@ class Video extends Model<InferAttributes<Video>, InferCreationAttributes<Video>
156156
foreignKey: 'targetId',
157157
// highlight-start
158158
// Foreign Keys must be disabled.
159-
constraints: false,
159+
foreignKeyConstraints: false,
160160
// This scope ensures that loading the "comments" association only loads comments that belong to videos.
161161
scope: {
162162
targetModel: 'video',
@@ -174,7 +174,7 @@ class Article extends Model<InferAttributes<Article>, InferCreationAttributes<Ar
174174
as: 'articles',
175175
},
176176
foreignKey: 'targetId',
177-
constraints: false,
177+
foreignKeyConstraints: false,
178178
scope: {
179179
targetModel: 'article',
180180
},

0 commit comments

Comments
 (0)