@@ -113,11 +113,11 @@ function RestQuery(config, auth, className, restWhere = {}, restOptions = {}, cl
113113// Returns a promise for the response - an object with optional keys
114114// 'results' and 'count'.
115115// TODO: consolidate the replaceX functions
116- RestQuery . prototype . execute = function ( ) {
116+ RestQuery . prototype . execute = function ( executeOptions ) {
117117 return Promise . resolve ( ) . then ( ( ) => {
118118 return this . buildRestWhere ( ) ;
119119 } ) . then ( ( ) => {
120- return this . runFind ( ) ;
120+ return this . runFind ( executeOptions ) ;
121121 } ) . then ( ( ) => {
122122 return this . runCount ( ) ;
123123 } ) . then ( ( ) => {
@@ -387,18 +387,22 @@ RestQuery.prototype.replaceDontSelect = function() {
387387
388388// Returns a promise for whether it was successful.
389389// Populates this.response with an object that only has 'results'.
390- RestQuery . prototype . runFind = function ( ) {
390+ RestQuery . prototype . runFind = function ( options = { } ) {
391391 if ( this . findOptions . limit === 0 ) {
392392 this . response = { results : [ ] } ;
393393 return Promise . resolve ( ) ;
394394 }
395+ let findOptions = Object . assign ( { } , this . findOptions ) ;
395396 if ( this . keys ) {
396- this . findOptions . keys = Array . from ( this . keys ) . map ( ( key ) => {
397+ findOptions . keys = Array . from ( this . keys ) . map ( ( key ) => {
397398 return key . split ( '.' ) [ 0 ] ;
398399 } ) ;
399400 }
401+ if ( options . op ) {
402+ findOptions . op = options . op ;
403+ }
400404 return this . config . database . find (
401- this . className , this . restWhere , this . findOptions ) . then ( ( results ) => {
405+ this . className , this . restWhere , findOptions ) . then ( ( results ) => {
402406 if ( this . className === '_User' ) {
403407 for ( var result of results ) {
404408 delete result . password ;
@@ -473,16 +477,15 @@ function includePath(config, auth, response, path, restOptions = {}) {
473477 return response ;
474478 }
475479 let pointersHash = { } ;
476- var objectIds = { } ;
477480 for ( var pointer of pointers ) {
478481 if ( ! pointer ) {
479482 continue ;
480483 }
481484 let className = pointer . className ;
482485 // only include the good pointers
483486 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 ) ;
486489 }
487490 }
488491
@@ -504,9 +507,9 @@ function includePath(config, auth, response, path, restOptions = {}) {
504507 }
505508
506509 let queryPromises = Object . keys ( pointersHash ) . map ( ( className ) => {
507- var where = { 'objectId' : { '$in' : pointersHash [ className ] } } ;
510+ let where = { 'objectId' : { '$in' : Array . from ( pointersHash [ className ] ) } } ;
508511 var query = new RestQuery ( config , auth , className , where , includeRestOptions ) ;
509- return query . execute ( ) . then ( ( results ) => {
512+ return query . execute ( { op : 'get' } ) . then ( ( results ) => {
510513 results . className = className ;
511514 return Promise . resolve ( results ) ;
512515 } )
0 commit comments