2015-12-06 59 views
2

Sequelize定义了两种模型:Post和Tag与多对多关联。如何在Sequelize ORM中限制连接行(多对多关联)?

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

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

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”。如何解决这个问题呢?

回答

1

在这里有相同的确切问题。从我收集的内容来看,要使用限制/偏移量,您需要include.separate,但不支持belongsToMany关联,因此您在本文发布时不支持您尝试执行的操作。

已经有人在处理它,你可以跟踪它 here

+0

还不工作家伙 –

相关问题