Sequelize onDelete不工作 [英] Sequelize onDelete not working

查看:722
本文介绍了Sequelize 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'
})

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

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