有两张表 article
与 tag
多对多关联
ArticleSchema.belongsToMany(CategorySchema, {
through: {
model: ArticleCategory,
unique: false // 取消联合主键的约定
},
as: 'category',
foreignKey: 'articleId',
constraints: false
})
CategorySchema.belongsToMany(ArticleSchema, {
through: {
model: ArticleCategory,
unique: false
},
as: 'article',
foreignKey: 'categoryId',
constraints: false
})
我现在需要通过tag
来筛选关联的article
应该怎么写呢
尝试了在 where
中查询,但是关联的属性是报错的,在 include
中来做筛选的话,将 tag
也进行了筛选
想要得到的结果就是 tag
传入 10
或者 11
或者 10和11
tag
都能返回图中的结果
有什么办法可以很简单的拿到呢