具有Sequelize关系的Sequelize FindOne查询在Sequelize中不起作用。Sequelize引发错误“无法读取未定义的属性'field'”

时间:2019-12-17 19:54:43

标签: mysql sequelize.js sequelize-cli sequelize-auto

我有类似 psychosocial_categories

的表格

enter image description here

psychosocial_categories_parts

enter image description here

vacancy_psychosocial_selected_answers 。通过关系

enter image description here

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 模型,就会引发错误:

无法读取未定义的属性“字段”

请向我建议正确的实施方式。 任何帮助将不胜感激。

0 个答案:

没有答案