@@ -325,6 +325,9 @@ function sanitizeDatabaseResult(originalObject, result) {
325
325
return Promise . resolve ( response ) ;
326
326
}
327
327
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.
328
331
DatabaseController . prototype . collectRelationUpdates = function ( className , objectId , update ) {
329
332
var ops = [ ] ;
330
333
var deleteMe = [ ] ;
@@ -361,9 +364,7 @@ DatabaseController.prototype.collectRelationUpdates = function(className, object
361
364
}
362
365
363
366
// 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
367
368
DatabaseController . prototype . handleRelationUpdates = function ( className , objectId , update , ops ) {
368
369
var pending = [ ] ;
369
370
objectId = update . objectId || objectId ;
@@ -540,7 +541,6 @@ DatabaseController.prototype.create = function(className, object, { acl } = {})
540
541
. then ( ( ) => this . loadSchema ( ) )
541
542
. then ( schemaController => {
542
543
return ( isMaster ? Promise . resolve ( ) : schemaController . validatePermission ( className , aclGroup , 'create' ) )
543
- . then ( ( ) => this . handleRelationUpdates ( className , null , object , relationUpdates ) )
544
544
. then ( ( ) => schemaController . enforceClassExists ( className ) )
545
545
. then ( ( ) => schemaController . reloadData ( ) )
546
546
. then ( ( ) => schemaController . getOneSchema ( className , true ) )
@@ -549,7 +549,11 @@ DatabaseController.prototype.create = function(className, object, { acl } = {})
549
549
flattenUpdateOperatorsForCreate ( object ) ;
550
550
return this . adapter . createObject ( className , SchemaController . convertSchemaToAdapterSchema ( schema ) , object ) ;
551
551
} )
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
+ } ) ;
553
557
} )
554
558
} ;
555
559
0 commit comments