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

Commit 82cf3572 by Mick Hansen

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

1 parent a30588aa
Showing with 11 additions and 4 deletions
...@@ -309,7 +309,9 @@ module.exports = (function() { ...@@ -309,7 +309,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)
...@@ -324,7 +326,10 @@ module.exports = (function() { ...@@ -324,7 +326,10 @@ module.exports = (function() {
, where = new Utils.where(self.target.rawAttributes[primaryKey], newInstance[primaryKey]) , where = new Utils.where(self.target.rawAttributes[primaryKey], newInstance[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) {
...@@ -337,10 +342,12 @@ module.exports = (function() { ...@@ -337,10 +342,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!