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

Commit 5c0bc021 by Mick Hansen

fix(hasMany): make sure the getter called by the setters use the transaction

1 parent b66d9ad9
Showing with 11 additions and 4 deletions
...@@ -262,7 +262,9 @@ module.exports = (function() { ...@@ -262,7 +262,9 @@ module.exports = (function() {
// define the returned customEventEmitter, which will emit the success event once everything is done // define the returned customEventEmitter, which will emit the success event once everything is done
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
instance[self.accessors.get]() instance[self.accessors.get]({
transaction: (defaultAttributes || {}).transaction
})
.success(function(oldAssociatedObjects) { .success(function(oldAssociatedObjects) {
var Class = Object(self.through) === self.through ? HasManyDoubleLinked : HasManySingleLinked var Class = Object(self.through) === self.through ? HasManyDoubleLinked : HasManySingleLinked
new Class(self, instance).injectSetter(emitter, oldAssociatedObjects, newAssociatedObjects, defaultAttributes) new Class(self, instance).injectSetter(emitter, oldAssociatedObjects, newAssociatedObjects, defaultAttributes)
...@@ -280,7 +282,10 @@ module.exports = (function() { ...@@ -280,7 +282,10 @@ module.exports = (function() {
where[newAssociatedObject.daoFactory.tableName+'.'+primaryKey] = newAssociatedObject[primaryKey] where[newAssociatedObject.daoFactory.tableName+'.'+primaryKey] = newAssociatedObject[primaryKey]
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
instance[self.accessors.get]({ where: where }) instance[self.accessors.get]({
where: where,
transaction: (additionalAttributes || {}).transaction
})
.proxy(emitter, {events: ['error', 'sql']}) .proxy(emitter, {events: ['error', 'sql']})
.success(function(currentAssociatedObjects) { .success(function(currentAssociatedObjects) {
if (currentAssociatedObjects.length === 0 || Object(self.through) === self.through) { if (currentAssociatedObjects.length === 0 || Object(self.through) === self.through) {
...@@ -293,10 +298,12 @@ module.exports = (function() { ...@@ -293,10 +298,12 @@ module.exports = (function() {
}).run() }).run()
} }
obj[this.accessors.remove] = function(oldAssociatedObject) { obj[this.accessors.remove] = function(oldAssociatedObject, options) {
var instance = this var instance = this
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
instance[self.accessors.get]().success(function(currentAssociatedObjects) { instance[self.accessors.get]({
transaction: (options || {}).transaction
}).success(function(currentAssociatedObjects) {
var newAssociations = [] var newAssociations = []
, oldAssociations = [] , oldAssociations = []
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!