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

Commit 5da749c8 by Maks Nemisj Committed by Sushant

port of 791b4c04fd383bdf721e72f617f8d3270f3c789e (#7334)

1 parent 6ca925b0
......@@ -158,12 +158,11 @@ Instance.prototype.getDataValue = function(key) {
* @param {any} value
*/
Instance.prototype.setDataValue = function(key, value) {
var originalValue = this.dataValues[key];
var originalValue = this._previousDataValues[key];
if (!Utils.isPrimitive(value) || value !== originalValue) {
this.changed(key, true);
}
this._previousDataValues[key] = originalValue;
this.dataValues[key] = value;
};
......@@ -310,6 +309,10 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
// If not raw, and there's a customer setter
if (!options.raw && this._customSetters[key]) {
this._customSetters[key].call(this, value, key);
if (!Utils.isPrimitive(value) && value !== null || value !== originalValue) {
this._previousDataValues[key] = originalValue;
this.changed(key, true);
}
} else {
// Check if we have included models, and if this key matches the include model names/aliases
......
......@@ -11,32 +11,27 @@ describe(Support.getTestDialectTeaser('Instance'), function () {
describe('previous', function () {
it('should return correct previous value', function () {
var Model = current.define('Model', {
text: {
type: DataTypes.STRING,
get: function (name) {
return this.getDataValue(name);
},
set: function (value, name) {
this.setDataValue(name, value);
}
text: DataTypes.STRING,
textCustom: {
type: DataTypes.STRING,
set: function (val) {
this.setDataValue('textCustom', val);
},
get: function () {
this.getDataValue('textCustom');
}
})
, instance
, shouldBeEmpty
, shouldBeA;
instance = Model.build({ text: 'a' }, {
isNewRecord: false
}
});
shouldBeEmpty = instance.previous('text');
var instance = Model.build({ text: 'a', textCustom: 'abc' });
expect(instance.previous('text')).to.be.not.ok;
expect(instance.previous('textCustom')).to.be.not.ok;
instance.set('text', 'b');
instance.set('textCustom', 'def');
shouldBeA = instance.previous('text');
expect(shouldBeEmpty).to.be.not.ok;
expect(shouldBeA).to.be.equal('a');
expect(instance.previous('text')).to.be.equal('a');
expect(instance.previous('textCustom')).to.be.equal('abc');
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!