Salut
Dans Sequelize V7 je crée une association BelongsToMany, Chapter as many Chapter

Mais quand je crée Association Adder j'ai une erreur:

TypeError: chapter.addChapter is not a function

Voici mon model Chpter :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
export class Chapter extends Model<InferAttributes<Chapter>, InferCreationAttributes<Chapter>> {
    @Attribute(DataTypes.INTEGER)
    @PrimaryKey
    @AutoIncrement
    declare id: CreationOptional<number>
 
    @BelongsToMany(() => Chapter, {
        through: "chapterChapter",
        inverse: {
          as: 'chapter',
        },
    })
    declare chapters?: NonAttribute<Chapter[]>;
    declare chapterChapters?: NonAttribute<Chapter[]>;
 
    declare addChapter: BelongsToManyAddAssociationMixin<Chapter, Chapter['id']>
 
}


Et voici une partie de mon chapter controler

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
 
 const chapter = await Chapter.findByPk(id)
 
  if (!chapter) {
      res.status(404).json({ error: 'Chapter not found' })
  }else{
      await chapter.addChapter( childChapterIds[0])   
      res.json(chapter)
  }


J'ai suivi ceci :
https://sequelize.org/docs/v7/associ...ion-adder-addx

Quelqu'un sait où se trouve mon erreur. Pour moi j'ai bien créé l'association dans le model avec le adder.

Merci pour l'aide