gpt4 book ai didi

javascript - Sequelize Include On 通过关联

转载 作者:行者123 更新时间:2023-12-03 22:16:47 25 4
gpt4 key购买 nike

是否有可能在 Sequelize 中通过关联包括在内..
我试过这样显示的代码,但它返回错误......
类型错误:无法读取未定义的属性“包含”
我正在使用 sql 方言

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'
}
]
}
}
]
});
这是与我的相同的github问题,但我还没有找到任何解决方案
[1]: https://github.com/sequelize/sequelize/issues/10828

最佳答案

你应该使用 Nested eager loading .例如,您的查询可能类似于:

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'
}
]

}
]
});

关于javascript - Sequelize Include On 通过关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64890300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com