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

Commit 2606346b by Jan Aagaard Meier

Don't update virtual attributes in Model.update. Fixes #2860

1 parent 34da9ce5
# Next # Next
- [BUG] Don't update virtual attributes in Model.update. Fixes [#2860](https://github.com/sequelize/sequelize/issues/2860)
- [BUG] Fix for newlines in hstore [#3383](https://github.com/sequelize/sequelize/issues/3383) - [BUG] Fix for newlines in hstore [#3383](https://github.com/sequelize/sequelize/issues/3383)
- [BUG] Fix unique key handling in Model.update [#3474](https://github.com/sequelize/sequelize/issues/3474) - [BUG] Fix unique key handling in Model.update [#3474](https://github.com/sequelize/sequelize/issues/3474)
- [BUG] Fix issue with Model.create() using fields not specifying and non-incremental primary key [#3458](https://github.com/sequelize/sequelize/issues/3458) - [BUG] Fix issue with Model.create() using fields not specifying and non-incremental primary key [#3458](https://github.com/sequelize/sequelize/issues/3458)
......
...@@ -1617,6 +1617,8 @@ module.exports = (function() { ...@@ -1617,6 +1617,8 @@ module.exports = (function() {
delete values[key]; delete values[key];
} }
}); });
} else {
options.fields = Object.keys(this.tableAttributes);
} }
if (this._timestampAttributes.updatedAt) { if (this._timestampAttributes.updatedAt) {
...@@ -1722,14 +1724,8 @@ module.exports = (function() { ...@@ -1722,14 +1724,8 @@ module.exports = (function() {
return [results.length, results]; return [results.length, results];
} }
Object.keys(valuesUse).forEach(function (attr) { valuesUse = Utils.mapValueFieldNames(valuesUse, options.fields, self);
if (self.rawAttributes[attr].field && self.rawAttributes[attr].field !== attr) { options = Utils.mapOptionFieldNames(options, self);
valuesUse[self.rawAttributes[attr].field] = valuesUse[attr];
delete valuesUse[attr];
}
});
Utils.mapOptionFieldNames(options, self);
// Run query to update all rows // Run query to update all rows
return self.QueryInterface.bulkUpdate(self.getTableName(options), valuesUse, options.where, options, self.tableAttributes).then(function(affectedRows) { return self.QueryInterface.bulkUpdate(self.getTableName(options), valuesUse, options.where, options, self.tableAttributes).then(function(affectedRows) {
......
...@@ -944,6 +944,30 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -944,6 +944,30 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
it('does not update virtual attributes', function () {
var User = this.sequelize.define('User', {
username: Sequelize.STRING,
virtual: Sequelize.VIRTUAL
});
return User.create({
username: 'jan'
}).then(function () {
return User.update({
username: 'kurt',
virtual: 'test'
}, {
where: {
username: 'jan'
}
});
}).then(function () {
return User.findAll();
}).spread(function (user) {
expect(user.username).to.equal('kurt');
});
});
it('sets updatedAt to the current timestamp', function() { it('sets updatedAt to the current timestamp', function() {
var data = [{ username: 'Peter', secretValue: '42' }, var data = [{ username: 'Peter', secretValue: '42' },
{ username: 'Paul', secretValue: '42' }, { username: 'Paul', secretValue: '42' },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!