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

Commit c03c9849 by Kenji Tayama

Fixed instance.destroy not working for models with "paranoid" and defaultValue o…

…f deletedAt set to non-null.
1 parent f482790b
......@@ -830,11 +830,12 @@ Instance.prototype.destroy = function(options) {
var where = this.where();
if (this.Model._timestampAttributes.deletedAt && options.force === false) {
var field = this.Model.rawAttributes[this.Model._timestampAttributes.deletedAt].field || this.Model._timestampAttributes.deletedAt;
var values = {};
var attribute = this.Model.rawAttributes[this.Model._timestampAttributes.deletedAt]
, field = attribute.field || this.Model._timestampAttributes.deletedAt
, values = {};
values[field] = new Date();
where[field] = null;
where[field] = attribute.hasOwnProperty('defaultValue') ? attribute.defaultValue : null;
this.setDataValue(field, values[field]);
......
......@@ -1483,8 +1483,13 @@ describe(Support.getTestDialectTeaser('Sequelize'), function() {
expect(Number(user.deletedAt)).to.equal(epoch);
return user.destroy();
}).then(function(destroyedUser) {
expect(destroyedUser.deletedAt).to.exist;
expect(Number(destroyedUser.deletedAt)).not.to.equal(epoch);
return destroyedUser.restore();
return User.findById(destroyedUser.id, { paranoid: false });
}).then(function(fetchedDestroyedUser) {
expect(fetchedDestroyedUser.deletedAt).to.exist;
expect(Number(fetchedDestroyedUser.deletedAt)).not.to.equal(epoch);
return fetchedDestroyedUser.restore();
}).then(function(restoredUser) {
expect(Number(restoredUser.deletedAt)).to.equal(epoch);
return User.destroy({where: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!