微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SequelizeJS 软删除在我运行迁移时不起作用

如何解决SequelizeJS 软删除在我运行迁移时不起作用

有人可以帮我看看我的代码哪里出错了,我尝试按照 this 进行软删除 但相反,它删除了我的整行,我的 deletedAt 不起作用。

这是我的迁移:

module.exports = {
    up: async (queryInterface,Sequelize) => {
        return queryInterface.createTable('pets',{
            ///i've remove some column that doesn't do anything here in my question

            deletedAt:
            {
                type: Sequelize.DATE,allowNull: true,}
        })
    },down: async (queryInterface,Sequelize) => {
        return queryInterface.dropTable('pets');
    }
};

这是我的模型

module.exports = (sequelize,DataTypes) => {
    class pet extends Model {
        static associate(models) {
        }
    };
    pet.init({
        name: {
            type: Sequelize.STRING,allowNull: false,},{
            paranoid: true,sequelize,modelName: 'pet',timestamps: false,});
    pet.associate = function (model) {
        pet.hasOne(model.order,{ foreignKey: "petId",targetKey: "petId" });
        pet.hasOne(model.category,{ as: 'category',foreignKey: 'petId' });
        pet.belongsToMany(model.tag,{
            as: 'tag',through: 'pet_tag',foreignKey: 'petId',otherKey: 'tagId',timestamps: false
        })
    }
    return pet;
};
 
I'm not sure how to check if I'm doing it correctly. 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。