【发布时间】:2015-11-19 19:38:13
【问题描述】:
鉴于以下 Sequelize 模型:
models.Post.belongsToMany(models.Tag, {
through: models.PostTag,
foreignKey: 'post_id',
as: 'tags'
});
models.Tag.belongsToMany(models.Post, {
through: models.PostTag,
foreignKey: 'tag_id'
});
我可以像这样查询带有 tag_id = 2 的标签的帖子:
models.Post.findAll({
include: [{
model: models.Tag,
as: 'tags',
where: {
tag_id: 2
}
}]
})
现在,我想查询所有已使用以下所有标签(tag_id)标记的帖子:2、5、17、87(或任何其他标签集)。 我使用 MySQL 作为数据库方言。似乎存在一些可能实现此目的的运算符($overlap、$contains、$contained),但也许这些是 PG 特定的?
【问题讨论】:
标签: sequelize.js