Mysql 在Sequelize.js中为关系表设置安全删除模式

Mysql 在Sequelize.js中为关系表设置安全删除模式,mysql,orm,sequelize.js,Mysql,Orm,Sequelize.js,因此,假设我们有Sequelize模型: var User = sequelize.define("User", { id: { type: DataTypes.STRING(45), allowNull: false, primaryKey: true }, password: { type: DataTypes.STRING(60),

因此,假设我们有Sequelize模型:

 var User = sequelize.define("User", {
        id: {
            type: DataTypes.STRING(45),
            allowNull: false,
            primaryKey: true
        },
        password: {
            type: DataTypes.STRING(60),
            allowNull: false
        },
        email: {
            type: DataTypes.STRING(45),
            allowNull: false,
            unique: true
        },
        firstName: {
            type: DataTypes.STRING(45),
            allowNull: true,
            defaultValue: null
        }
    },
    {
            tableName: 'profiles',
            classMethods: {
                associate: function(models) {
                    User.belongsToMany(User, {through: 'friends', as:'friend'});
                }
            }
        });

调用associate()方法后,它将创建一个额外的表
friends
,其中包含列
userId
friendsid
createdAt
updatedAt
。这种情况下,我需要在安全删除模式下使用此表,换句话说,我必须以某种方式添加“已删除”列。我试图在belongtomany的属性中使用
paranoid:true
,但没有成功。有什么办法吗

也许您可以创建一个名为Friend的模型/表。你可以设置偏执狂:在那个模型中为真。当您删除一个用户时,它会保留该模型中用户的朋友关系

我希望它能起作用