@@ -396,15 +396,14 @@ DatabaseController.prototype.owningIds = function(className, key, relatedIds) {
396
396
// equal-to-pointer constraints on relation fields.
397
397
// Returns a promise that resolves when query is mutated
398
398
DatabaseController . prototype . reduceInRelation = function ( className , query , schema ) {
399
+
399
400
// Search for an in-relation or equal-to-relation
400
401
// Make it sequential for now, not sure of paralleization side effects
401
402
if ( query [ '$or' ] ) {
402
403
let ors = query [ '$or' ] ;
403
404
return Promise . all ( ors . map ( ( aQuery , index ) => {
404
405
return this . reduceInRelation ( className , aQuery , schema ) . then ( ( aQuery ) => {
405
- if ( aQuery ) {
406
- query [ '$or' ] [ index ] = aQuery ;
407
- }
406
+ query [ '$or' ] [ index ] = aQuery ;
408
407
} )
409
408
} ) ) ;
410
409
}
@@ -416,7 +415,7 @@ DatabaseController.prototype.reduceInRelation = function(className, query, schem
416
415
let t = schema . getExpectedType ( className , key ) ;
417
416
let match = t ? t . match ( / ^ r e l a t i o n < ( .* ) > $ / ) : false ;
418
417
if ( ! match ) {
419
- return ;
418
+ return Promise . resolve ( query ) ;
420
419
}
421
420
let relatedClassName = match [ 1 ] ;
422
421
let relatedIds ;
@@ -455,7 +454,10 @@ DatabaseController.prototype.reduceRelationKeys = function(className, query) {
455
454
relatedTo . key ,
456
455
relatedTo . object . objectId ) . then ( ( ids ) => {
457
456
delete query [ '$relatedTo' ] ;
458
- query [ 'objectId' ] = { '$in' : ids } ;
457
+ query . objectId = query . objectId || { } ;
458
+ let queryIn = query . objectId [ '$in' ] || [ ] ;
459
+ queryIn = queryIn . concat ( ids ) ;
460
+ query [ 'objectId' ] = { '$in' : queryIn } ;
459
461
return this . reduceRelationKeys ( className , query ) ;
460
462
} ) ;
461
463
}
0 commit comments