Answer the question
In order to leave comments, you need to log in
How to fetch with limit for many-to-many models in Sequelize ORM?
There are two models defined with Sequelize: Post and Tag, which are many-to-many related:
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
Error: N:M associations are not supported with hasMany. Use belongsToMany instead
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question