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

Commit f32b3072 by Sushant Committed by Mick Hansen

restore ignore field from deletedAt attribute (#6806)

* (fix) restore ignore field from deletedAt attr

* [ci skip] change log changes
1 parent c7a3019d
# Future
- [FIXED] `restore` now uses `field` from `deletedAt`
# 3.24.7
- [FIXED] MSSQL bulkInsertQuery when options and attributes are not passed [#6782]
......@@ -14,7 +17,7 @@
- [FIXED] Default options for insert queries [#6644](https://github.com/sequelize/sequelize/pull/6644)
# 3.24.3
- [ADDED] Backport of grouped limit include support
- [ADDED] Backport of grouped limit include support
- [ADDED] Export datatypes [#6578](https://github.com/sequelize/sequelize/pull/6578)
# 3.24.2
......
......@@ -2376,7 +2376,7 @@ Model.prototype.restore = function(options) {
, deletedAtAttribute = self.rawAttributes[deletedAtCol]
, deletedAtDefaultValue = deletedAtAttribute.hasOwnProperty('defaultValue') ? deletedAtAttribute.defaultValue : null;
attrValueHash[deletedAtCol] = deletedAtDefaultValue;
attrValueHash[deletedAtAttribute.field || deletedAtCol] = deletedAtDefaultValue;
options.omitNull = false;
return self.QueryInterface.bulkUpdate(self.getTableName(options), attrValueHash, options.where, options, self._timestampAttributes.deletedAt);
}).tap(function() {
......
'use strict';
/* jshint -W030 */
var Support = require(__dirname + '/../support');
var DataTypes = require(__dirname + '/../../../lib/data-types');
var chai = require('chai');
var expect = chai.expect;
var sinon = require('sinon');
var Support = require(__dirname + '/../support');
describe(Support.getTestDialectTeaser('Model'), function () {
describe('paranoid', function () {
before(function () {
this.clock = sinon.useFakeTimers();
});
after(function () {
this.clock.restore();
});
it('should be able to soft delete with timestamps', function () {
var Account = this.sequelize.define('Account', {
ownerId: {
type: DataTypes.INTEGER,
allowNull: false,
field: 'owner_id'
},
name: {
type: DataTypes.STRING
}
}, {
paranoid: true,
timestamps: true
});
return Account.sync({force: true})
.then(function () { return Account.create({ ownerId: 12 }); })
.then(function () { return Account.count(); })
.then(function (count) {
expect(count).to.be.equal(1);
return Account.destroy({ where: { ownerId: 12 }});
})
.then(function () { return Account.count(); })
.then(function (count) {
expect(count).to.be.equal(0);
return Account.count({ paranoid: false });
})
.then(function (count) {
expect(count).to.be.equal(1);
return Account.restore({ where: { ownerId: 12 }});
})
.then(function () { return Account.count(); })
.then(function (count) {
expect(count).to.be.equal(1);
});
});
it('should be able to soft delete without timestamps', function () {
var Account = this.sequelize.define('Account', {
ownerId: {
type: DataTypes.INTEGER,
allowNull: false,
field: 'owner_id'
},
name: {
type: DataTypes.STRING
},
deletedAt: {
type: DataTypes.DATE,
allowNull: true,
field: 'deleted_at'
}
}, {
paranoid: true,
timestamps: true,
deletedAt: 'deletedAt',
createdAt: false,
updatedAt: false
});
return Account.sync({force: true})
.then(function () { return Account.create({ ownerId: 12 }); })
.then(function () { return Account.count(); })
.then(function (count) {
expect(count).to.be.equal(1);
return Account.destroy({ where: { ownerId: 12 }});
})
.then(function () { return Account.count(); })
.then(function (count) {
expect(count).to.be.equal(0);
return Account.count({ paranoid: false });
})
.then(function (count) {
expect(count).to.be.equal(1);
return Account.restore({ where: { ownerId: 12 }});
})
.then(function () { return Account.count(); })
.then(function (count) {
expect(count).to.be.equal(1);
});
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!