@@ -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,7 +387,7 @@ 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 ( ) ;
@@ -398,7 +398,7 @@ RestQuery.prototype.runFind = function() {
398398 } ) ;
399399 }
400400 return this . config . database . find (
401- this . className , this . restWhere , this . findOptions ) . then ( ( results ) => {
401+ this . className , this . restWhere , this . findOptions , options . op ) . then ( ( results ) => {
402402 if ( this . className === '_User' ) {
403403 for ( var result of results ) {
404404 delete result . password ;
@@ -473,16 +473,15 @@ function includePath(config, auth, response, path, restOptions = {}) {
473473 return response ;
474474 }
475475 let pointersHash = { } ;
476- var objectIds = { } ;
477476 for ( var pointer of pointers ) {
478477 if ( ! pointer ) {
479478 continue ;
480479 }
481480 let className = pointer . className ;
482481 // only include the good pointers
483482 if ( className ) {
484- pointersHash [ className ] = pointersHash [ className ] || [ ] ;
485- pointersHash [ className ] . push ( pointer . objectId ) ;
483+ pointersHash [ className ] = pointersHash [ className ] || new Set ( ) ;
484+ pointersHash [ className ] . add ( pointer . objectId ) ;
486485 }
487486 }
488487
@@ -504,9 +503,9 @@ function includePath(config, auth, response, path, restOptions = {}) {
504503 }
505504
506505 let queryPromises = Object . keys ( pointersHash ) . map ( ( className ) => {
507- var where = { 'objectId' : { '$in' : pointersHash [ className ] } } ;
506+ let where = { 'objectId' : { '$in' : Array . from ( pointersHash [ className ] ) } } ;
508507 var query = new RestQuery ( config , auth , className , where , includeRestOptions ) ;
509- return query . execute ( ) . then ( ( results ) => {
508+ return query . execute ( { op : 'get' } ) . then ( ( results ) => {
510509 results . className = className ;
511510 return Promise . resolve ( results ) ;
512511 } )
0 commit comments