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”。如何解决这个问题呢?
还不工作家伙 –