更新时间:2021-10-22 08:48:15
我认为你应该使用 belongsToMany
关联在这里.
I think you should use belongsToMany
association here.
你可以这样定义关联
Product.belongsToMany(Category, { through: ProductCategory, foreignKey: 'product_id' });
Category.belongsToMany(Product, { through: ProductCategory, foreignKey: 'category_id' });
查询可以是
Product.findAll({
include: [Category]
}).then((res) => {
console.log(res);
})