mysql - Sequelize - afterBulkUpdate() 如果更新与否如何获取
问题描述
如果实例用户更新与否,我如何知道在一个钩子 afterBulkUpdate() 内?
UserController.js
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
// But inside a Model how I know if updated or not?
User.addHook('afterBulkUpdate', (options) => {
// user.isUpdated?
});
我不能使用 afterUpdate(),没有运行到我,即使individualHooks: true
像这样使用:
UserController.js
const [isUpdated] = await User.update(
fields,
{where, individualHooks: true}
);
我正在使用 MySQL。有什么解决办法吗?
解决方案
const user = sequelize.define("user",
{
first_name: { type: DataTypes.STRING, trim: true },
...
},
hooks: {
// afterUpdate(instance, options) {
// let changed = instance._changed;
// console.log(changed, options);
// }
},
}
);
推荐阅读
- android - Android 错误:权限被拒绝:启动 Intent
- c++ - 如何对参数化模板函数进行类型推导
- string - 在 CMD 中添加空格以选择字符串时加入行不起作用
- excel - 将 Excel 行保存为不同的文件格式时如何停止提示闪烁?
- javascript - 如果相同的字符不相邻,为什么输出不正确?
- c++ - Armadillo/C++:如何将元素从向量分配到立方体管?
- reactjs - ReactNative - 不变违规:requireNativeComponent:在 UI 管理器中找不到“RNCSafeareview”
- selenium-webdriver - 如何通过 Java 使用 Selenium WebDriver 等到所有加载器消失
- javascript - 我们可以在 Telr 中将身份验证事务作为连续权限事务进行吗?
- php - 用于 unicode 数组的 in_array 的替代方案