sequelize 创建多对多关系报错?

定义关联关系:

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

theme_product为中间表

报错信息:

 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
阅读 6.4k
3 个回答

我是通过这样的方式实现的,不知道对你有没有帮助。
Wordbook为word(单词表)和book(教材表)的关系表
Wordbook.belongsTo(WordModel, {
foreignKey: "wordid",
constraints: false,
});
// BelongsTo关联表示一对多关系的外键存在于源模型。
Wordbook.belongsTo(BookModel, {
foreignKey: "bookid",
constraints: false,
});

推荐问题