-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Including a virtual field with no other changed values gives an ER_EMPTY_QUERY error #6356
Description
What you are doing?
The code below demonstrates the problem.
var Sequelize = require('sequelize');
var database = new Sequelize( /*fill in database configurations*/ );
var TestModel = database.define('TestModel', {
realField: Sequelize.INTEGER,
virtField: {
type: Sequelize.VIRTUAL,
get: function() {
return 4;
}
}
}, {
tableName: 'test_model',
timestamps: false
});
TestModel.sync();
TestModel.create({ realField: 8 })
.then(function(result) {
result.update({ virtField: 4, realField: 6 })
.then(function() {
console.log('When the instance has changed, it still works.');
});
result.update({ virtField: 4 })
.then(function() {
console.log('If virtField has a setter, this will print. Otherwise there\'ll be an error.');
});
});What do you expect to happen?
Since Sequelize doesn't fuss when there's a virtual field without a setter in an update normally, I would assume that intended functionality would be for there to be no error.
What is actually happening?
As-is, my code will work fine for the first update call, the one that changes both realField and virtField. However, the second query will throw an error. It would seem that Sequelize doesn't handle it well when a changed virtual field with no setter is present in the returned object.
If there is a setter function present, e.g. js set: function() {}, there's no error.
It's worth noting that this may be unique to databases without timestamps, because timestamps will presumably always be updated.
Dialect: mysql
Database version: mysql@2.11.1
Sequelize version: 3.23.6