Node.js + sequelize:同一模型的两个外键

时间:2018-06-01 12:02:22

标签: node.js model sequelize.js

我需要在名为DataSurvey的模型中添加两​​个外键,这些外键指向另一个名为AppPerson的模型

  DataSurvey.associate = function(models) {
DataSurvey.belongsTo(models.AppPerson); // this should have the name idResponsible
DataSurvey.belongsTo(models.AppPerson); // this should have the name idConcerned  };

我该怎么做?

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

这很好用

    DataSurvey.belongsTo(models.AppPerson, {as: 'Responsible'});
    DataSurvey.belongsTo(models.AppPerson, {as: 'Concerned'});