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

Commit bb107197 by Mick Hansen

fix(instance/attribute/field): an instance should not contain values per their f…

…ield prop after create, fixes #2468
1 parent 9ab475de
Showing with 36 additions and 0 deletions
......@@ -622,6 +622,12 @@ module.exports = (function() {
throw err;
}).tap(function(result) {
// Transfer database generated values (defaults, autoincrement, etc)
Object.keys(self.Model.rawAttributes).forEach(function (attr) {
if (self.Model.rawAttributes[attr].field && values[self.Model.rawAttributes[attr].field] !== undefined && self.Model.rawAttributes[attr].field !== attr) {
values[attr] = values[self.Model.rawAttributes[attr].field];
delete values[self.Model.rawAttributes[attr].field];
}
});
values = _.extend(values, result.dataValues);
// Ensure new values are on Instance, and reset previousDataValues
......
......@@ -197,6 +197,36 @@ describe(Support.getTestDialectTeaser("Model"), function () {
});
});
it('should not contain the field properties after create', function () {
var Model = this.sequelize.define('test', {
id: {
type : Sequelize.INTEGER.UNSIGNED,
field : 'test_id',
autoIncrement: true,
primaryKey : true,
validate : {
min: 1
}
},
title: {
allowNull: false,
type : Sequelize.STRING(255),
field : 'test_title',
}
}, {
timestamps: true,
underscored: true,
freezeTableName: true
});
return Model.sync({force: true}).then(function () {
return Model.create({title: 'test'}).then(function (data) {
expect(data.get('test_title')).to.be.an('undefined');
expect(data.get('test_id')).to.be.an('undefined');
});
});
});
it('should make the aliased auto incremented primary key available after create', function () {
var self = this;
return this.User.create({
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!