Skip to content

Commit 04b5bab

Browse files
committed
Always run relation udpates last
1 parent 86beaaf commit 04b5bab

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Controllers/DatabaseController.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ function sanitizeDatabaseResult(originalObject, result) {
325325
return Promise.resolve(response);
326326
}
327327

328+
// Collect all relation-updating operations from a REST-format update.
329+
// Returns a list of all relation updates to perform
330+
// This mutates update.
328331
DatabaseController.prototype.collectRelationUpdates = function(className, objectId, update) {
329332
var ops = [];
330333
var deleteMe = [];
@@ -361,9 +364,7 @@ DatabaseController.prototype.collectRelationUpdates = function(className, object
361364
}
362365

363366
// Processes relation-updating operations from a REST-format update.
364-
// Returns a promise that resolves successfully when these are
365-
// processed.
366-
// This mutates update.
367+
// Returns a promise that resolves when all updates have been performed
367368
DatabaseController.prototype.handleRelationUpdates = function(className, objectId, update, ops) {
368369
var pending = [];
369370
objectId = update.objectId || objectId;
@@ -540,7 +541,6 @@ DatabaseController.prototype.create = function(className, object, { acl } = {})
540541
.then(() => this.loadSchema())
541542
.then(schemaController => {
542543
return (isMaster ? Promise.resolve() : schemaController.validatePermission(className, aclGroup, 'create'))
543-
.then(() => this.handleRelationUpdates(className, null, object, relationUpdates))
544544
.then(() => schemaController.enforceClassExists(className))
545545
.then(() => schemaController.reloadData())
546546
.then(() => schemaController.getOneSchema(className, true))
@@ -549,7 +549,11 @@ DatabaseController.prototype.create = function(className, object, { acl } = {})
549549
flattenUpdateOperatorsForCreate(object);
550550
return this.adapter.createObject(className, SchemaController.convertSchemaToAdapterSchema(schema), object);
551551
})
552-
.then(result => sanitizeDatabaseResult(originalObject, result.ops[0]));
552+
.then(result => {
553+
return this.handleRelationUpdates(className, null, object, relationUpdates).then(() => {
554+
return sanitizeDatabaseResult(originalObject, result.ops[0])
555+
});
556+
});
553557
})
554558
};
555559

0 commit comments

Comments
 (0)