如何在续集中使用偏执狂? [英] How to use paranoid in sequelize?

查看:38
本文介绍了如何在续集中使用偏执狂?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想删除一个条目,我是 Sequelize 的新手我不会直接删除我有一个单独的字段来使其处于活动状态和非活动状态.所以我想有一个 deteledAT 字段在删除条目时自动更新.我有什么办法可以对付偏执狂.

I am a newbie to Sequelize if I want to delete an entry I will not delete directly I have a separate field to make it active and inactive. So I want to have a deteledAT field to update automatically while deleting an entry. Is there any way I can do with paranoid.

推荐答案

在您的模型中添加:

  paranoid: true,
  timestamps: true,

小例子:

sequelize.define(
    'example',
    {
      id: {
        type: DataTypes.UUID,
        allowNull: false,
        primaryKey: true,
        unique: true,
        defaultValue: sequelize.literal('uuid_generate_v1()'),
      }
    },
    {
      tableName: 'example',
      createdAt: 'created_at',
      updatedAt: 'updated_at',
      deletedAt: 'deteledAT',
      paranoid: true,
      timestamps: true,
    },
  );

因此,我们将获得带有 4 列(id、created_at、updated_at、deteledAT)的 example 表,并且当您调用 destroy 方法时,在 中 sequeslize 插入日期deteledAT 列和选择(findOne、findAll 等)在deletedAT 不为空时自动忽略所有行

So, we'll get example table with 4 colums (id, created_at, updated_at, deteledAT) and when you call destroy method sequeslize insert date in deteledAT column and for select (findOne, findAll etc) automatically ignore all rows when deletedAT is not null

这篇关于如何在续集中使用偏执狂?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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