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

Commit 4f95f176 by daleoooo Committed by Jan Aagaard Meier

Fixed: 6310 (#6963)

1 parent 86c567de
...@@ -57,6 +57,7 @@ ConnectionManager.prototype.connect = function(config) { ...@@ -57,6 +57,7 @@ ConnectionManager.prototype.connect = function(config) {
host: config.host, host: config.host,
port: config.port, port: config.port,
user: config.username, user: config.username,
flags: '-FOUND_ROWS',
password: config.password, password: config.password,
database: config.database, database: config.database,
timezone: self.sequelize.options.timezone, timezone: self.sequelize.options.timezone,
......
...@@ -331,6 +331,28 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -331,6 +331,28 @@ describe(Support.getTestDialectTeaser('Model'), function() {
}); });
}); });
it('does not update when setting current values', function() {
return this.User.create({ id: 42, username: 'john' }).bind(this).then(function() {
return this.User.findById(42);
}).then(function(user) {
return this.User.upsert({ id: user.id, username: user.username });
}).then(function(created) {
if (dialect === 'sqlite') {
expect(created).to.be.undefined;
} else {
// After set node-mysql flags = '-FOUND_ROWS' in connection of mysql,
// result from upsert should be false when upsert a row to its current value
// https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
expect(created).to.equal(false);
}
});
});
it('Works when two separate uniqueKeys are passed', function() { it('Works when two separate uniqueKeys are passed', function() {
var User = this.sequelize.define('User', { var User = this.sequelize.define('User', {
username: { username: {
...@@ -352,18 +374,18 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -352,18 +374,18 @@ describe(Support.getTestDialectTeaser('Model'), function() {
if (dialect === 'sqlite') { if (dialect === 'sqlite') {
expect(created).to.be.undefined; expect(created).to.be.undefined;
} else { } else {
expect(created).to.be.ok; expect(created).to.be.ok;
} }
clock.tick(1000); clock.tick(1000);
return User.upsert({ username: 'user1', email: 'user1@domain.ext', city: 'New City' }); return User.upsert({ username: 'user1', email: 'user1@domain.ext', city: 'New City' });
}).then(function(created) { }).then(function(created) {
if (dialect === 'sqlite') { if (dialect === 'sqlite') {
expect(created).to.be.undefined; expect(created).to.be.undefined;
} else { } else {
expect(created).not.to.be.ok; expect(created).not.to.be.ok;
} }
clock.tick(1000); clock.tick(1000);
return User.findOne({ where: { username: 'user1', email: 'user1@domain.ext' }}); return User.findOne({ where: { username: 'user1', email: 'user1@domain.ext' }});
}) })
.then(function(user) { .then(function(user) {
expect(user.createdAt).to.be.ok; expect(user.createdAt).to.be.ok;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!