gpt4 book ai didi

sequelize.js - 如何在 Sequelize 中使用偏执狂?

转载 作者:行者123 更新时间:2023-12-04 04:04:56 24 4
gpt4 key购买 nike

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

最佳答案

在你的模型中添加:

  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: 'deletedAt',
paranoid: true,
timestamps: true,
},
);

因此,我们将获得具有 4 个列(id、created_at、updated_at、deletedAt)的 example 表,并且当您调用 destroy 方法时,将在 中插入日期deletedAt 列和 for select(findOne、findAll 等)在 deletedAt 不为 null 时自动忽略所有行

关于sequelize.js - 如何在 Sequelize 中使用偏执狂?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54687518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com