我正在尝试创建一个钩子beforeBulkUpdate并获取字段的新值和先前值。我尝试.reload()在模型上使用,_previousDataValues但它们仅适用于实例,而不适用于批量创建和更新(我正在使用批量更新)。有没有办法使用beforeBulkUpdate钩子获取字段的先前值?
beforeBulkUpdate: (person) => {
console.log(person.name) // 'John' (new name)
Person.findOne({ where: { id: input.id } }).then(person => {
person.reload().then(() => {
console.log(person.name) // 'John' (expected old name, but returns new name)
})
})
}
Run Code Online (Sandbox Code Playgroud) sequelize.js ×1