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});
在“标签”页面上,我想获取相关标签数据和相关文章,并通过分页显示它们。因此,我应该限制文章数量。但是,如果我尝试在“include”内部限制它们,那么...
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”。如何解决这个问题?