我在两个表之间有多对多的注册关系:学生和课程是这样的:
var Enrollment = sequelize.define('Enrollment', {
EnrollmentType: {
//some attributes
},
{
associate: function(models){
models.Person.belongsToMany(models.Course, { as: 'CourseEnroll', through: { model: Enrollment }, foreignKey: 'StudentEnrollId'});
models.Course.belongsToMany(models.Person, { as: 'StudentEnroll', through: {model: Enrollment},foreignKey: 'CourseEnrollId'});
}
}
但是我需要在Period Table中添加第三个Key,以便在Enrollment表上有3个唯一的键组合。我试过了:
Enrollment.belongsTo(models.Period, { as: 'PeriodEnroll', foreignKey: 'PeriodEnrollId', primaryKey: true,});
但是没有工作,我也尝试用其他一些表做第三个belongsToMany但是没有用。我该如何存档?