Reputation: 578
Is It possible in sequelize to include on through association.. i have tried like this shown code but it returns error...
TypeError: Cannot read property 'includes' of undefined
i m using sql dialect
let instructorGrade = await model.Instructor.findOne({
where: { id },
attributes: ['id'],
include: [
{
model: model.SchoolGrade,
as: 'instructorSchoolGrades',
through: {
include: [
{
model: model.Grade,
as: 'schoolGrades'
},
{
model: model.Section,
as: 'schoolGradeSection'
}
]
}
}
]
});
Here is the github issue which is same as mine but i havent find any solution [1]: https://github.com/sequelize/sequelize/issues/10828
Upvotes: 2
Views: 1616
Reputation: 3638
you should use Nested eager loading. So for example, you query might be something like:
let instructorGrade = await model.Instructor.findOne({
where: { id },
attributes: ['id'],
include: [
{
model: model.SchoolGrade,
as: 'instructorSchoolGrades',
include: [
{
model: model.Grade,
as: 'schoolGrades'
},
{
model: model.Section,
as: 'schoolGradeSection'
}
]
}
]
});
Upvotes: 2