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

Commit 1c412756 by Sascha Depold

Merge pull request #1644 from sequelize/hotfix/transaction-support-for-association-setter

Fix for #1637
2 parents 4ac8c613 5d912233
...@@ -87,7 +87,8 @@ module.exports = (function() { ...@@ -87,7 +87,8 @@ module.exports = (function() {
var instance = this var instance = this
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
instance[association.accessors.get]().success(function(oldInstance) { instance[association.accessors.get](options)
.success(function(oldInstance) {
if (oldInstance) { if (oldInstance) {
oldInstance[association.identifier] = null oldInstance[association.identifier] = null
oldInstance oldInstance
...@@ -113,6 +114,7 @@ module.exports = (function() { ...@@ -113,6 +114,7 @@ module.exports = (function() {
} }
} }
}) })
.proxy(emitter, { events: ['sql'] })
}).run() }).run()
} }
......
...@@ -24,7 +24,7 @@ module.exports = (function() { ...@@ -24,7 +24,7 @@ module.exports = (function() {
} }
this.client.query(this.sql, function(err, results, fields) { this.client.query(this.sql, function(err, results, fields) {
this.emit('sql', this.sql) this.emit('sql', this.sql, this.options.uuid)
if (err) { if (err) {
err.sql = sql err.sql = sql
...@@ -38,5 +38,3 @@ module.exports = (function() { ...@@ -38,5 +38,3 @@ module.exports = (function() {
return Query return Query
})() })()
...@@ -38,12 +38,12 @@ module.exports = (function() { ...@@ -38,12 +38,12 @@ module.exports = (function() {
query.on('error', function(err) { query.on('error', function(err) {
receivedError = true receivedError = true
err.sql = sql err.sql = sql
self.emit('sql', sql) self.emit('sql', sql, self.options.uuid)
self.emit('error', err, self.callee) self.emit('error', err, self.callee)
}) })
query.on('end', function(result) { query.on('end', function(result) {
self.emit('sql', self.sql) self.emit('sql', self.sql, self.options.uuid)
if (receivedError) { if (receivedError) {
return return
......
...@@ -36,13 +36,13 @@ module.exports = (function() { ...@@ -36,13 +36,13 @@ module.exports = (function() {
if (self.sql.indexOf('-- ') === 0) { if (self.sql.indexOf('-- ') === 0) {
// the sql query starts with a comment. don't bother the server with that ... // the sql query starts with a comment. don't bother the server with that ...
Utils.tick(function() { Utils.tick(function() {
self.emit('sql', self.sql) self.emit('sql', self.sql, self.options.uuid)
self.emit('success', null) self.emit('success', null)
}) })
} else { } else {
self.database[getDatabaseMethod.call(self)](self.sql, function(err, results) { self.database[getDatabaseMethod.call(self)](self.sql, function(err, results) {
// allow clients to listen to sql to do their own logging or whatnot // allow clients to listen to sql to do their own logging or whatnot
self.emit('sql', self.sql) self.emit('sql', self.sql, self.options.uuid)
if (err) { if (err) {
err.sql = self.sql err.sql = self.sql
......
...@@ -127,8 +127,9 @@ module.exports = (function() { ...@@ -127,8 +127,9 @@ module.exports = (function() {
options.events = Utils._.difference(options.events, options.skipEvents) options.events = Utils._.difference(options.events, options.skipEvents)
options.events.forEach(function (eventKey) { options.events.forEach(function (eventKey) {
this.on(eventKey, function (result) { this.on(eventKey, function () {
emitter.emit(eventKey, result) var args = [ eventKey ].concat([].slice.apply(arguments))
emitter.emit.apply(emitter, args)
}) })
}.bind(this)) }.bind(this))
......
...@@ -892,9 +892,7 @@ module.exports = (function() { ...@@ -892,9 +892,7 @@ module.exports = (function() {
this.emit(methodName, err) this.emit(methodName, err)
emitter.emit('error', err) emitter.emit('error', err)
}.bind(this)) }.bind(this))
.on('sql', function(sql) { .proxy(emitter, { events: ['sql'] })
emitter.emit('sql', sql)
})
}.bind(this) }.bind(this)
if (!!emitter) { if (!!emitter) {
......
...@@ -90,7 +90,9 @@ describe(Support.getTestDialectTeaser("HasOne"), function() { ...@@ -90,7 +90,9 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
User.create({ username: 'foo' }).success(function(user) { User.create({ username: 'foo' }).success(function(user) {
Group.create({ name: 'bar' }).success(function(group) { Group.create({ name: 'bar' }).success(function(group) {
sequelize.transaction(function(t) { sequelize.transaction(function(t) {
group.setUser(user, { transaction: t }).success(function() { group
.setUser(user, { transaction: t })
.success(function() {
Group.all().success(function(groups) { Group.all().success(function(groups) {
groups[0].getUser().success(function(associatedUser) { groups[0].getUser().success(function(associatedUser) {
expect(associatedUser).to.be.null expect(associatedUser).to.be.null
...@@ -98,6 +100,9 @@ describe(Support.getTestDialectTeaser("HasOne"), function() { ...@@ -98,6 +100,9 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
}) })
}) })
}) })
.on('sql', function(sql, uuid) {
expect(uuid).to.not.equal('default')
})
}) })
}) })
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!