我有类似 psychosocial_categories
的表格和 psychosocial_categories_parts
和 vacancy_psychosocial_selected_answers 。通过关系
db.PsychosocialCategoriesParts.belongsTo(db.PsychosocialCategories, { foreignKey: 'psychosocial_categories_id' });
db.VacancyPsychosocialSelectedAnswers.belongsTo(db.PsychosocialCategoriesParts, { foreignKey: 'psychosocial_categories_parts_id' });
db.VacancyPsychosocialSelectedAnswers.belongsTo(db.Vacancies,{ foreignKey: 'vacancy_id'});
db.Vacancies.hasMany(db.VacancyPsychosocialSelectedAnswers,{ foreignKey: 'vacancy_id'});
db.VacancyPsychosocialSelectedAnswers.belongsToMany(db.Vacancies, {
through: db.PsychosocialCategoriesParts,
foreignKey: 'psychosocial_categories_parts_id'
});
当我这样写时:-
Vacancies.findOne({
include: [
{
model: VacancyPsychosocialSelectedAnswers,
include: [
{ model: PsychosocialCategoriesParts}
]
}
],
where: {
id:1001
}
})
一旦我在包含中添加 PsychosocialCategoriesParts 模型,就会引发错误:
无法读取未定义的属性“字段”
请向我建议正确的实施方式。 任何帮助将不胜感激。