不要怂,就是干,撸起袖子干!

Commit 100b2ddb by Miroslav Committed by Sushant

fix(model/update): propagate paranoid to individualHooks query (#10369)

1 parent d610e949
Showing with 37 additions and 1 deletions
......@@ -2907,7 +2907,13 @@ class Model {
// Get instances and run beforeUpdate hook on each record individually
if (options.individualHooks) {
return this.findAll({ where: options.where, transaction: options.transaction, logging: options.logging, benchmark: options.benchmark }).then(_instances => {
return this.findAll({
where: options.where,
transaction: options.transaction,
logging: options.logging,
benchmark: options.benchmark,
paranoid: options.paranoid
}).then(_instances => {
instances = _instances;
if (!instances.length) {
return [];
......
......@@ -1194,6 +1194,36 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it('calls update hook for soft deleted objects', function() {
const hookSpy = sinon.spy();
const User = this.sequelize.define('User',
{ username: DataTypes.STRING },
{ paranoid: true, hooks: { beforeUpdate: hookSpy } }
);
return this.sequelize.sync({ force: true }).then(() => {
return User.bulkCreate([
{ username: 'user1' }
]);
}).then(() => {
return User.destroy({
where: {
username: 'user1'
}
});
}).then(() => {
return User.update(
{ username: 'updUser1' },
{ paranoid: false, where: { username: 'user1' }, individualHooks: true });
}).then(() => {
return User.findOne({ where: { username: 'updUser1' }, paranoid: false });
}).then( user => {
expect(user).to.not.be.null;
expect(user.username).to.eq('updUser1');
expect(hookSpy).to.have.been.called;
});
});
if (dialect === 'postgres') {
it('returns the affected rows if `options.returning` is true', function() {
const data = [{ username: 'Peter', secretValue: '42' },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!