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

Commit 523fbe8c by Ricardo Lopes Committed by Jan Aagaard Meier

Fix defaultValues getting overwritten

1 parent 23787de5
# Future
- [FIXED] Fix defaultValues getting overwritten on build
# 3.21.0 # 3.21.0
- [FIXED] Confirmed that values modified in validation hooks are preserved [#3534](https://github.com/sequelize/sequelize/issues/3534) - [FIXED] Confirmed that values modified in validation hooks are preserved [#3534](https://github.com/sequelize/sequelize/issues/3534)
- [FIXED] Support lower case type names in SQLite [#5482](https://github.com/sequelize/sequelize/issues/5482) - [FIXED] Support lower case type names in SQLite [#5482](https://github.com/sequelize/sequelize/issues/5482)
......
...@@ -22,10 +22,9 @@ var initValues = function(values, options) { ...@@ -22,10 +22,9 @@ var initValues = function(values, options) {
defaults = {}; defaults = {};
if (this.Model._hasDefaultValues) { if (this.Model._hasDefaultValues) {
Utils._.each(this.Model._defaultValues, function(valueFn, key) { defaults = _.mapValues(this.Model._defaultValues, function(valueFn) {
if (defaults[key] === undefined) { var value = valueFn();
defaults[key] = valueFn(); return (value && value._isSequelizeMethod) ? value : _.cloneDeep(value);
}
}); });
} }
......
...@@ -94,5 +94,21 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -94,5 +94,21 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
expect(instance.get('number2')).not.to.be.undefined; expect(instance.get('number2')).not.to.be.undefined;
expect(instance.get('number2')).to.equal(2); expect(instance.get('number2')).to.equal(2);
}); });
it('should clone the default values', function () {
var Model = current.define('Model', {
data: {
type: DataTypes.JSONB,
defaultValue: { foo: 'bar' }
}
})
, instance;
instance = Model.build();
instance.data.foo = 'biz';
expect(instance.get('data')).to.eql({ foo: 'biz' });
expect(Model.build().get('data')).to.eql({ foo: 'bar' });
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!