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

Commit 3f6f0764 by Mick Hansen

fix: mapValueFieldNames should only replace field names if value exists in targe…

…t, closes #3581, #3663
1 parent 40814b76
......@@ -1630,7 +1630,7 @@ module.exports = (function() {
}
});
} else {
options.fields = Object.keys(this.tableAttributes);
options.fields = _.intersection(Object.keys(values), Object.keys(this.tableAttributes));
}
if (this._timestampAttributes.updatedAt) {
......
......@@ -164,13 +164,14 @@ var Utils = module.exports = {
fields.forEach(function(attr) {
if (dataValues[attr] !== undefined && !Model._isVirtualAttribute(attr)) {
values[attr] = dataValues[attr];
}
// Field name mapping
if (Model.rawAttributes[attr] && Model.rawAttributes[attr].field && Model.rawAttributes[attr].field !== attr) {
values[Model.rawAttributes[attr].field] = values[attr];
delete values[attr];
}
}
});
return values;
......
'use strict';
/* jshint -W030 */
var Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + '/../../../lib/data-types');
describe(Support.getTestDialectTeaser('Model'), function() {
describe('update', function () {
it('should only update the passed fields', function () {
var Account = this.sequelize.define('Account', {
ownerId: {
type: DataTypes.INTEGER,
allowNull: false,
field: 'owner_id'
},
name: {
type: DataTypes.STRING
}
});
return Account.sync({force: true, logging: console.log}).then(function () {
return Account.create({
ownerId: 2
}).then(function (account) {
return Account.update({
name: Math.random().toString()
}, {
where: {
id: account.get('id')
}
});
});
});
});
});
});
\ 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!