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

Commit ab0570d5 by Maks Nemisj Committed by Sushant

fix correct previous value (#7186)

1 parent 6b597dc2
# Future
- [FIXED] `previous` method gave wrong value back [#7189](https://github.com/sequelize/sequelize/pull/7189)
# 3.30.1 # 3.30.1
- [FIXED] `sourceKey` FOR `hasMany` now also works if a `where` was specified in an `include` [#7141](https://github.com/sequelize/sequelize/issues/7141) - [FIXED] `sourceKey` FOR `hasMany` now also works if a `where` was specified in an `include` [#7141](https://github.com/sequelize/sequelize/issues/7141)
- [CHANGED] Updated deprecated `node-uuid` package to `uuid` [#7148](https://github.com/sequelize/sequelize/pull/7148) - [CHANGED] Updated deprecated `node-uuid` package to `uuid` [#7148](https://github.com/sequelize/sequelize/pull/7148)
......
...@@ -158,11 +158,12 @@ Instance.prototype.getDataValue = function(key) { ...@@ -158,11 +158,12 @@ Instance.prototype.getDataValue = function(key) {
* @param {any} value * @param {any} value
*/ */
Instance.prototype.setDataValue = function(key, value) { Instance.prototype.setDataValue = function(key, value) {
var originalValue = this._previousDataValues[key]; var originalValue = this.dataValues[key];
if (!Utils.isPrimitive(value) || value !== originalValue) { if (!Utils.isPrimitive(value) || value !== originalValue) {
this.changed(key, true); this.changed(key, true);
} }
this._previousDataValues[key] = originalValue;
this.dataValues[key] = value; this.dataValues[key] = value;
}; };
......
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + '/../../../lib/data-types')
, current = Support.sequelize;
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);
}
}
})
, instance
, shouldBeEmpty
, shouldBeA;
instance = Model.build({ text: 'a' }, {
isNewRecord: false
});
shouldBeEmpty = instance.previous('text');
instance.set('text', 'b');
shouldBeA = instance.previous('text');
expect(shouldBeEmpty).to.be.not.ok;
expect(shouldBeA).to.be.equal('a');
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!