Nested include in sequelize?
Solution provided didn't work for me, this is the typescript version I use and guessing the sequelize versions:
// sequelize-typescript
models.products.findAll({
where,
include: [{
model: Comment,
include: [User]
}]
});
// without typescript (guessing here)
models.products.findAll({
where,
include: [{
model: models.comments,
include: [{
model: models.users
}]
}]
});
There is a very simple and concise way! https://sequelize.org/docs/v6/advanced-association-concepts/eager-loading/#including-everything
// Fetch all models associated with User
User.findAll({ include: { all: true }});
// Fetch all models associated with User and their nested associations (recursively)
User.findAll({ include: { all: true, nested: true }});
models.products.findAll({
include: [
{model: models.comments, include: [models.comments.users] }
]
})