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

Commit e7c298f2 by Mick Hansen

Merge pull request #5468 from glutentag/fix-defaultvalue

Fix issue with undefined column having defaultvalue
2 parents c04c5bac 6133955f
...@@ -55,6 +55,7 @@ var initValues = function(values, options) { ...@@ -55,6 +55,7 @@ var initValues = function(values, options) {
for (key in defaults) { for (key in defaults) {
if (values[key] === undefined) { if (values[key] === undefined) {
this.set(key, Utils.toDefaultValue(defaults[key]), defaultsOptions); this.set(key, Utils.toDefaultValue(defaults[key]), defaultsOptions);
delete values[key];
} }
} }
} }
......
...@@ -71,5 +71,28 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -71,5 +71,28 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
expect(instance.get('id')).not.to.be.undefined; expect(instance.get('id')).not.to.be.undefined;
expect(instance.get('id')).to.be.ok; expect(instance.get('id')).to.be.ok;
}); });
it('should populate undefined columns with default value', function () {
var Model = current.define('Model', {
number1: {
type: DataTypes.INTEGER,
defaultValue: 1
},
number2: {
type: DataTypes.INTEGER,
defaultValue: 2
}
})
, instance;
instance = Model.build({
number1: undefined
});
expect(instance.get('number1')).not.to.be.undefined;
expect(instance.get('number1')).to.equal(1);
expect(instance.get('number2')).not.to.be.undefined;
expect(instance.get('number2')).to.equal(2);
});
}); });
}); });
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!