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

Commit 31b9c0ba by Mick Hansen

fix(sql/update): use new whereQuery in updateQuery, closes #3113

1 parent 6ebe8b17
......@@ -2,6 +2,7 @@
- [BUG] Fixed regression with `DataTypes.ARRAY(DataTypes.STRING(length))` [#3106](https://github.com/sequelize/sequelize/issues/3106)
- [BUG] Fixed regression where `.or([{key: value}, {key: value, key2: value}])` would result in 3 `A OR B OR C` rather than `A OR (B AND C)` [#3107](https://github.com/sequelize/sequelize/issues/3107)
- [BUG] Fixed regression with `DataTypes.DECIMAL(10)` resulting in `10, undefined` [#3119](https://github.com/sequelize/sequelize/issues/3119)
- [BUG] Fixed issue with dangling `WHERE ` query on `Model.update(values, {where: {}})` [#3113](https://github.com/sequelize/sequelize/issues/3113)
# 2.0.1
- [BUG] Fixed issue with empty `include.where`
......
......@@ -300,7 +300,7 @@ module.exports = (function() {
, outputFragment
, modelAttributeMap = {};
query = 'UPDATE <%= table %> SET <%= values %><%= output %> WHERE <%= where %>';
query = 'UPDATE <%= table %> SET <%= values %><%= output %> <%= where %>';
if (this._dialect.supports['LIMIT ON UPDATE'] && options.limit) {
query += ' LIMIT ' + this.escape(options.limit) + ' ';
......@@ -340,14 +340,14 @@ module.exports = (function() {
table: this.quoteTable(tableName),
values: values.join(','),
output: outputFragment,
where: this.getWhereConditions(where)
where: this.whereQuery(where)
};
if (values.length === 0) {
return '';
}
return Utils._.template(query)(replacements);
return Utils._.template(query)(replacements).trim();
},
/*
......@@ -1748,6 +1748,9 @@ module.exports = (function() {
value = this.escape(value, field);
}
// Really retarded BC^TM
if (key === undefined) key = 'id';
key = this.quoteIdentifier(key);
if (options.prefix) {
......
......@@ -2363,7 +2363,7 @@ describe(Support.getTestDialectTeaser('HasMany'), function() {
// `WHERE` clause
var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model);
return user.QueryInterface.update(user, tableName, {id: 999}, user.id);
return user.QueryInterface.update(user, tableName, {id: 999}, {id: user.id});
}).then(function() {
return Task.findAll();
}).then(function(tasks) {
......
......@@ -438,7 +438,7 @@ if (Support.dialectIsMySQL()) {
arguments: ['myTable', {name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}, {id: 2}],
expectation: "UPDATE `myTable` SET `name`='foo',`birthday`='2011-03-27 10:01:55' WHERE `id` = 2"
}, {
arguments: ['myTable', {name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}, 2],
arguments: ['myTable', {name: 'foo', birthday: new Date(Date.UTC(2011, 2, 27, 10, 1, 55))}, {id: 2}],
expectation: "UPDATE `myTable` SET `name`='foo',`birthday`='2011-03-27 10:01:55' WHERE `id` = 2"
}, {
arguments: ['myTable', {bar: 2}, {name: 'foo'}],
......
......@@ -687,7 +687,7 @@ if (dialect.match(/^postgres/)) {
arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, {id: 2}],
expectation: "UPDATE \"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.000 +00:00' WHERE \"id\" = 2"
}, {
arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, 2],
arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, {id: 2}],
expectation: "UPDATE \"myTable\" SET \"name\"='foo',\"birthday\"='2011-03-27 10:01:55.000 +00:00' WHERE \"id\" = 2"
}, {
arguments: ['myTable', {bar: 2}, {name: 'foo'}],
......@@ -746,7 +746,7 @@ if (dialect.match(/^postgres/)) {
expectation: "UPDATE myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id = 2",
context: {options: {quoteIdentifiers: false}}
}, {
arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, 2],
arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, {id: 2}],
expectation: "UPDATE myTable SET name='foo',birthday='2011-03-27 10:01:55.000 +00:00' WHERE id = 2",
context: {options: {quoteIdentifiers: false}}
}, {
......
......@@ -423,7 +423,7 @@ if (dialect === 'sqlite') {
arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, {id: 2}],
expectation: "UPDATE `myTable` SET `name`='foo',`birthday`='2011-03-27 10:01:55.000 +00:00' WHERE `id` = 2"
}, {
arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, 2],
arguments: ['myTable', {name: 'foo', birthday: moment('2011-03-27 10:01:55 +0000', 'YYYY-MM-DD HH:mm:ss Z').toDate()}, {id: 2}],
expectation: "UPDATE `myTable` SET `name`='foo',`birthday`='2011-03-27 10:01:55.000 +00:00' WHERE `id` = 2"
}, {
arguments: ['myTable', { name: 'foo' }, { id: 2 }],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!