@@ -113,11 +113,11 @@ function RestQuery(config, auth, className, restWhere = {}, restOptions = {}, cl
113
113
// Returns a promise for the response - an object with optional keys
114
114
// 'results' and 'count'.
115
115
// TODO: consolidate the replaceX functions
116
- RestQuery . prototype . execute = function ( ) {
116
+ RestQuery . prototype . execute = function ( executeOptions ) {
117
117
return Promise . resolve ( ) . then ( ( ) => {
118
118
return this . buildRestWhere ( ) ;
119
119
} ) . then ( ( ) => {
120
- return this . runFind ( ) ;
120
+ return this . runFind ( executeOptions ) ;
121
121
} ) . then ( ( ) => {
122
122
return this . runCount ( ) ;
123
123
} ) . then ( ( ) => {
@@ -387,18 +387,22 @@ RestQuery.prototype.replaceDontSelect = function() {
387
387
388
388
// Returns a promise for whether it was successful.
389
389
// Populates this.response with an object that only has 'results'.
390
- RestQuery . prototype . runFind = function ( ) {
390
+ RestQuery . prototype . runFind = function ( options = { } ) {
391
391
if ( this . findOptions . limit === 0 ) {
392
392
this . response = { results : [ ] } ;
393
393
return Promise . resolve ( ) ;
394
394
}
395
+ let findOptions = Object . assign ( { } , this . findOptions ) ;
395
396
if ( this . keys ) {
396
- this . findOptions . keys = Array . from ( this . keys ) . map ( ( key ) => {
397
+ findOptions . keys = Array . from ( this . keys ) . map ( ( key ) => {
397
398
return key . split ( '.' ) [ 0 ] ;
398
399
} ) ;
399
400
}
401
+ if ( options . op ) {
402
+ findOptions . op = options . op ;
403
+ }
400
404
return this . config . database . find (
401
- this . className , this . restWhere , this . findOptions ) . then ( ( results ) => {
405
+ this . className , this . restWhere , findOptions ) . then ( ( results ) => {
402
406
if ( this . className === '_User' ) {
403
407
for ( var result of results ) {
404
408
delete result . password ;
@@ -473,16 +477,15 @@ function includePath(config, auth, response, path, restOptions = {}) {
473
477
return response ;
474
478
}
475
479
let pointersHash = { } ;
476
- var objectIds = { } ;
477
480
for ( var pointer of pointers ) {
478
481
if ( ! pointer ) {
479
482
continue ;
480
483
}
481
484
let className = pointer . className ;
482
485
// only include the good pointers
483
486
if ( className ) {
484
- pointersHash [ className ] = pointersHash [ className ] || [ ] ;
485
- pointersHash [ className ] . push ( pointer . objectId ) ;
487
+ pointersHash [ className ] = pointersHash [ className ] || new Set ( ) ;
488
+ pointersHash [ className ] . add ( pointer . objectId ) ;
486
489
}
487
490
}
488
491
@@ -504,9 +507,9 @@ function includePath(config, auth, response, path, restOptions = {}) {
504
507
}
505
508
506
509
let queryPromises = Object . keys ( pointersHash ) . map ( ( className ) => {
507
- var where = { 'objectId' : { '$in' : pointersHash [ className ] } } ;
510
+ let where = { 'objectId' : { '$in' : Array . from ( pointersHash [ className ] ) } } ;
508
511
var query = new RestQuery ( config , auth , className , where , includeRestOptions ) ;
509
- return query . execute ( ) . then ( ( results ) => {
512
+ return query . execute ( { op : 'get' } ) . then ( ( results ) => {
510
513
results . className = className ;
511
514
return Promise . resolve ( results ) ;
512
515
} )
0 commit comments