首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Sequelize - afterBulkUpdate()如何获取更新或未更新

Sequelize - afterBulkUpdate()如何获取更新或未更新
EN

Stack Overflow用户
提问于 2021-03-07 02:19:02
回答 2查看 186关注 0票数 0

我怎么知道钩子afterBulkUpdate()里面的实例用户是否更新了?

UserController.js

代码语言:javascript
运行
复制
const [isUpdated] = await User.update(
    fields,
    {where}
);

// Where I know if updated or not! isUpdated is 1 when updated, 0 when not updated

User.js

代码语言:javascript
运行
复制
// But inside a Model how I know if updated or not?
User.addHook('afterBulkUpdate', (options) => {
    // user.isUpdated?
});

我不能使用afterUpdate(),甚至像这样使用individualHooks: true

UserController.js

代码语言:javascript
运行
复制
const [isUpdated] = await User.update(
    fields,
    {where, individualHooks: true}
);

我正在使用MySQL。有什么解决方案吗?

EN

Stack Overflow用户

发布于 2021-03-07 02:33:36

代码语言:javascript
运行
复制
const user = sequelize.define("user",
    {
      first_name: { type: DataTypes.STRING, trim: true },
      ...
     
    },
      hooks: {
        // afterUpdate(instance, options) {
        //   let changed = instance._changed;
        //   console.log(changed, options);
        // }
      },
    }
  );
票数 2
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66509135

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档