1- import { BelongsToManyOptions as OriginBelongsToManyOptions , Model , ThroughOptions } from "sequelize" ;
2-
31import { BaseAssociation } from '../shared/base-association' ;
42import { BelongsToManyOptions } from './belongs-to-many-options' ;
53import { ModelNotInitializedError } from '../../model/shared/model-not-initialized-error' ;
@@ -8,44 +6,46 @@ import {ModelClassGetter} from "../../model/shared/model-class-getter";
86import { Association } from "../shared/association" ;
97import { Sequelize } from "../../sequelize/sequelize/sequelize" ;
108import { UnionAssociationOptions } from "../shared/union-association-options" ;
9+ import { ModelType } from "../../model/model/model" ;
10+ import { ThroughOptions } from "../through/through-options" ;
1111
12- export class BelongsToManyAssociation extends BaseAssociation {
12+ export class BelongsToManyAssociation < TCreationAttributes , TModelAttributes , TCreationAttributesThrough , TModelAttributesThrough > extends BaseAssociation < TCreationAttributes , TModelAttributes > {
1313
14- constructor ( associatedClassGetter : ModelClassGetter ,
15- protected options : BelongsToManyOptions ) {
14+ constructor ( associatedClassGetter : ModelClassGetter < TCreationAttributes , TModelAttributes > ,
15+ protected options : BelongsToManyOptions < TCreationAttributesThrough , TModelAttributesThrough > ) {
1616 super ( associatedClassGetter , options ) ;
1717 }
1818
1919 getAssociation ( ) : Association {
2020 return Association . BelongsToMany ;
2121 }
2222
23- getSequelizeOptions ( model : typeof Model ,
23+ getSequelizeOptions ( model : ModelType < TCreationAttributes , TModelAttributes > ,
2424 sequelize : Sequelize ) : UnionAssociationOptions {
25- const options : OriginBelongsToManyOptions = { ...this . options as any } ;
25+ const options : BelongsToManyOptions < TCreationAttributesThrough , TModelAttributesThrough > = { ...this . options } ;
2626 const associatedClass = this . getAssociatedClass ( ) ;
2727 const throughOptions = this . getThroughOptions ( sequelize ) ;
2828
2929 const throughModel = typeof throughOptions === 'object' && typeof throughOptions . model !== "string" ? throughOptions . model : undefined ;
3030 options . through = throughOptions ;
31- options . foreignKey = getForeignKeyOptions ( model , throughModel , this . options . foreignKey ) ;
32- options . otherKey = getForeignKeyOptions ( associatedClass , throughModel , this . options . otherKey ) ;
31+ options . foreignKey = getForeignKeyOptions ( model , throughModel as any , this . options . foreignKey ) ;
32+ options . otherKey = getForeignKeyOptions ( associatedClass , throughModel as any , this . options . otherKey ) ;
3333
3434 return options ;
3535 }
3636
37- private getThroughOptions ( sequelize : Sequelize ) : ThroughOptions | string {
37+ private getThroughOptions ( sequelize : Sequelize ) : ThroughOptions < TCreationAttributesThrough , TModelAttributesThrough > | string {
3838 const through = this . options . through ;
3939 const throughModel = typeof through === 'object' ? through . model : through ;
40- const throughOptions : ThroughOptions =
40+ const throughOptions : ThroughOptions < TCreationAttributesThrough , TModelAttributesThrough > =
4141 typeof through === 'object' ? { ...through } : { } as any ;
4242
4343 if ( typeof throughModel === 'function' ) {
4444 const throughModelClass = sequelize . model ( throughModel ( ) ) ;
4545 if ( ! throughModelClass . isInitialized ) {
4646 throw new ModelNotInitializedError ( throughModelClass , 'Association cannot be resolved.' ) ;
4747 }
48- throughOptions . model = throughModelClass ;
48+ throughOptions . model = throughModelClass as any ;
4949 } else {
5050 return throughModel ;
5151 }
0 commit comments