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

Commit 729575e0 by Maks Nemisj Committed by Sushant

master:fix-previous-value (#7189)

1 parent 0c2f20b4
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
- [FIXED] scope method syntax loses parameters when used multiple times [#7058](https://github.com/sequelize/sequelize/issues/7058) - [FIXED] scope method syntax loses parameters when used multiple times [#7058](https://github.com/sequelize/sequelize/issues/7058)
- [INTERNAL] Updated to `generic-pool@3.1.6` [#7109](https://github.com/sequelize/sequelize/issues/7109) - [INTERNAL] Updated to `generic-pool@3.1.6` [#7109](https://github.com/sequelize/sequelize/issues/7109)
- [FIXED] findAll throws error if attributes option is formatted incorrectly [#7162](https://github.com/sequelize/sequelize/issues/7163) - [FIXED] findAll throws error if attributes option is formatted incorrectly [#7162](https://github.com/sequelize/sequelize/issues/7163)
- [FIXED] previous gave wrong value back [#7189](https://github.com/sequelize/sequelize/pull/7189)
## BC breaks: ## BC breaks:
- `DATEONLY` now returns string in `YYYY-MM-DD` format rather than `Date` type - `DATEONLY` now returns string in `YYYY-MM-DD` format rather than `Date` type
......
...@@ -2977,11 +2977,12 @@ class Model { ...@@ -2977,11 +2977,12 @@ class Model {
* @param {any} value * @param {any} value
*/ */
setDataValue(key, value) { setDataValue(key, value) {
const originalValue = this._previousDataValues[key]; const 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!