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

Commit 30045647 by Tiago Ribeiro

Improve `previous()` instance method

1 parent 12e2a873
...@@ -420,7 +420,13 @@ Instance.prototype.changed = function(key, value) { ...@@ -420,7 +420,13 @@ Instance.prototype.changed = function(key, value) {
* @return {any} * @return {any}
*/ */
Instance.prototype.previous = function(key) { Instance.prototype.previous = function(key) {
return this._previousDataValues[key]; if (key) {
return this._previousDataValues[key];
}
return _.pick(this._previousDataValues, function(value, key) {
return this.changed(key);
}, this);
}; };
Instance.prototype._setInclude = function(key, value, options) { Instance.prototype._setInclude = function(key, value, options) {
......
...@@ -450,6 +450,23 @@ describe(Support.getTestDialectTeaser('DAO'), function() { ...@@ -450,6 +450,23 @@ describe(Support.getTestDialectTeaser('DAO'), function() {
}); });
describe('previous', function() { describe('previous', function() {
it('should return an object with the previous values', function() {
var User = this.sequelize.define('User', {
name: { type: DataTypes.STRING },
title: { type: DataTypes.STRING }
});
var user = User.build({
name: 'Jan Meier',
title: 'Mr'
});
user.set('name', 'Mick Hansen');
user.set('title', 'Dr');
expect(user.previous()).to.eql({ name: 'Jan Meier', title: 'Mr' });
});
it('should return the previous value', function() { it('should return the previous value', function() {
var User = this.sequelize.define('User', { var User = this.sequelize.define('User', {
name: {type: DataTypes.STRING} name: {type: DataTypes.STRING}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!