File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -19,14 +19,19 @@ export interface FilterQueryAttributes {
19
19
sorted : string
20
20
}
21
21
22
- export default {
22
+ const models = {
23
23
Role,
24
24
User,
25
25
UserRole,
26
26
}
27
27
28
- /*
29
- Models Association
30
- */
28
+ export default models
31
29
32
- User . belongsToMany ( Role , { through : UserRole } )
30
+ export type MyModels = typeof models
31
+
32
+ Object . entries ( models ) . map ( ( [ , model ] ) => {
33
+ if ( model ?. associate ) {
34
+ model . associate ( models )
35
+ }
36
+ return model
37
+ } )
Original file line number Diff line number Diff line change @@ -93,4 +93,8 @@ User.prototype.comparePassword = function (candidatePassword: string) {
93
93
} )
94
94
}
95
95
96
+ User . associate = ( models ) => {
97
+ User . belongsToMany ( models . Role , { through : models . UserRole } )
98
+ }
99
+
96
100
export default User
You can’t perform that action at this time.
0 commit comments