续集 onDelete 不起作用 [英] Sequelize onDelete not working

查看:34
本文介绍了续集 onDelete 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两个模型之间定义了如下关联:

I have associations between two models defined as below:

对于联系模型(在单独的文件中)

For Contact Model (in a separate file)

classMethods: {
      associate: function (models){
         Contact.belongsTo(models.User)
      }
}

对于用户(在一个单独的文件中)

For User(in a separate file)

classMethods: {
     associate: function (models){
        User.hasMany(models.Contact, {onDelete: 'CASCADE'})
     }
}

问题是当删除用户时,与该用户相关的联系人没有删除任何关于我做错了什么的建议会有帮助吗?

The problem is when deleting the user the contact related to the user is not deleting any advice on what am I doing wrong would be helpful?

提前致谢

推荐答案

我认为你需要反过来定义它.

I think you need to define it the other way around.

Contact.belongsTo(models.Users, {
    foreignKeyConstraint: true
    , onDelete: 'cascade'
})

这篇关于续集 onDelete 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆