0
我有兩個使用Sequelize cli創建的模型;第一個型號是user_number
,第二個型號是emailSign
。破壞級聯在Sequelize orm中不起作用
這是我user_number
型號:
'use strict';
module.exports = function(sequelize, DataTypes) {
var user_number = sequelize.define('user_number', {
user_id: DataTypes.INTEGER,
callRoute_id: DataTypes.INTEGER,
password: DataTypes.STRING,
}, {
underscored: true,
classMethods: {
associate: function(models) {
// associations can be defined here
user_number.hasMany(models.emailSign, {
foreignKey: 'user_number_id',
onDelete: "CASCADE",
});
}
}
});
return user_number;
};
這是我emailSign
型號:
'use strict';
module.exports = function(sequelize, DataTypes) {
var emailSign = sequelize.define('emailSign', {
email: DataTypes.STRING,
user_number_id: DataTypes.INTEGER
}, {
underscored: true,
classMethods: {
associate: function(models) {
// associations can be defined here
emailSign.belongsTo(models.user_number, {
foreignKey: 'user_number_id',
})
}
}
});
return emailSign;
};
我想摧毀user_number
級聯刪除emailSign
。我對破壞代碼是
User_number.destroy({where:{id : 5}}).then(function(){
resp.status(200);
)
user_number
ID爲5被刪除,但emailSign
不會被刪除。
我該如何刪除相關的emailSign
?
我Sequelize版本是3.30.4
https://stackoverflow.com/questions/23634139/sequelize-ondelete-not-working – FiftiN
坦但它不起作用 – majid