【发布时间】:2021-03-16 02:29:32
【问题描述】:
【问题讨论】:
标签: node.js sequelize.js sequelize-cli
【问题讨论】:
标签: node.js sequelize.js sequelize-cli
您需要在 'projects.model.js' 中使用 onDelete: 'CASCADE':
const Projects = sequelize.define('projects', other_stuffs);
...
Projects.associate = function (models) {
this.belongsToMany(models.get('configurations'), {
through: 'project_configurations',
foreignKey: 'project_id',
onUpdate: 'CASCADE', // optional
onDelete: 'CASCADE',
});
return this;
};
...
在'configurations.model.js':
const Configurations = sequelize.define('configurations', other_stuffs);
...
Configurations.associate = function (models) {
this.belongsToMany(models.get('projects'), {
through: 'project_configurations',
foreignKey: 'configurations_id',
onUpdate: 'CASCADE', // optional
onDelete: 'CASCADE',
});
return this;
};
...
【讨论】: