如何在Sequelize ORM中限制连接行(多对多关联)?

Sequelize定义了两个模型:Post和Tag与多对多的关联。

Post.belongsToMany(db.Tag, {through: 'post_tag', foreignKey: 'post_id', timestamps: false}); Tag.belongsToMany(db.Post, {through: 'post_tag', foreignKey: 'tag_id',timestamps: false}); 

在“标签”页面上,我想获取标签数据,相关的post,并用分页显示。 所以我应该限制职位。 但是,如果我试图限制他们内“包括”

 Tag.findOne({ where: {url: req.params.url}, include: [{ model : Post, limit: 10 }] }).then(function(tag) { //handling results }); 

我得到以下错误:

 Unhandled rejection Error: Only HasMany associations support include.separate 

如果我尝试切换到“HasMany”关联,我得到以下错误

 Error: N:M associations are not supported with hasMany. Use belongsToMany instead 

而从另一边的文档说,限制选项“只支持include.separate = true”。 如何解决这个问题呢?

在这里有相同的确切问题。 从我所搜集到的内容来看,使用limit / offset你需要include.separate,这对于belongsToMany关联来说是不被支持的,所以你在这篇文章的时候不支持你所要做的。

已经有人在这里工作,你可以在这里跟踪。