Sequelize hasMany through another table

前端 未结 2 748
Happy的楠姐
Happy的楠姐 2021-02-20 16:34

Okay so i have the following three models

Module:

    var Module = sequelize.define(\'module\', {
        id: DataTypes.INT         


        
2条回答
  •  有刺的猬
    2021-02-20 17:35

    Steven's answer did not work for me but switching the foreign keys.

    Competence.belongsToMany(Module, {
      through: Module_has_competence,
      as: 'module',
      foreignKey: 'competence_id'
    });
    Module.belongsToMany(Competence, {
      through: Module_has_competence,
      as: 'competence',
      foreignKey: 'module_id'
    });
    

提交回复
热议问题