Associating 3 tables in SEQUELIZE

Can you try this, also?

user.js

classMethods: {
  associate: function(models) {
    // associations can be defined here
    User.belongsToMany(models.School, {
        through: {
            model: models.UserSchool
        },
        foreignKey: 'uuid'
    });
  }
}

school.js

classMethods: {
  associate: function(models) {
    //associations can be defined here
    School.belongsToMany(models.User, {
        through: {
            model: models.UserSchool
        },
        foreignKey: 'school_id'
    });
  }
}

No association in UserSchool.


User.belongsToMany(models.School, {
    through: {
        model: models.UserSchool
    },
    foreignKey: 'uuid'
});

School.belongsToMany(models.User, {
    through: {
        model: models.UserSchool
    },
    foreignKey: 'school_id'
});

This should solve your problem.

Tags:

Sequelize.Js