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 {
1919 sorted : string
2020}
2121
22- export default {
22+ const models = {
2323 Role,
2424 User,
2525 UserRole,
2626}
2727
28- /*
29- Models Association
30- */
28+ export default models
3129
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) {
9393 } )
9494}
9595
96+ User . associate = ( models ) => {
97+ User . belongsToMany ( models . Role , { through : models . UserRole } )
98+ }
99+
96100export default User
You can’t perform that action at this time.
0 commit comments