Does sequelize create a many-to-many relationship to report an error?

define association:

 Theme.belongsToMany(Product,{through:theme_product,foreignKey:"theme_id"})
 Product.belongsToMany(Theme,{through:theme_product,foreignKey:"product_id"})

theme_product is the intermediate table

error message:

 throw new Error(this.name + ".belongsToMany called with something that\"snot a subclass of Sequelize.Model");
      ^

Error: Theme.belongsToMany called with something that"s not a subclass of Sequelize.Model
Dec.18,2021
The

problem has been resolved and the two models are not under the same sequelize instance.
refer to this project: https://codeshelper.com/a/11.


Hello, I also encountered this error. How did you solve it? can you share your code in detail?


I realized it in this way. I don't know if it's helpful to you.
Wordbook is the relationship table between word (vocabulary list) and book (material list)
Wordbook.belongsTo (WordModel, {
foreignKey: "wordid",
constraints: false,
});
/ / BelongsTo association indicates that the foreign key of an one-to-many relationship exists in the source model.
Wordbook.belongsTo (BookModel, {
foreignKey: "bookid",
constraints: false,
});

Menu