Skip to content

Commit

Permalink
👍 fixes #1298
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Mar 31, 2016
1 parent 9c528c6 commit ca7d858
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,39 +449,42 @@ function includePath(config, auth, response, path) {
if (pointers.length == 0) {
return response;
}
let pointersHash = {};
var className = null;
var objectIds = {};
for (var pointer of pointers) {
if (className === null) {
className = pointer.className;
} else {
if (className != pointer.className) {
throw new Parse.Error(Parse.Error.INVALID_JSON,
'inconsistent type data for include');
}
let className = pointer.className;
// only include the good pointers
if (className) {
pointersHash[className] = pointersHash[className] || [];
pointersHash[className].push(pointer.objectId);
}
objectIds[pointer.objectId] = true;
}
if (!className) {
throw new Parse.Error(Parse.Error.INVALID_JSON,
'bad pointers');
}

let queryPromises = Object.keys(pointersHash).map((className) => {
var where = {'objectId': {'$in': pointersHash[className]}};
var query = new RestQuery(config, auth, className, where);
return query.execute().then((results) => {
results.className = className;
return Promise.resolve(results);
})
})

// Get the objects for all these object ids
var where = {'objectId': {'$in': Object.keys(objectIds)}};
var query = new RestQuery(config, auth, className, where);
return query.execute().then((includeResponse) => {
var replace = {};
for (var obj of includeResponse.results) {
obj.__type = 'Object';
obj.className = className;

if(className == "_User"){
delete obj.sessionToken;
return Promise.all(queryPromises).then((responses) => {
var replace = responses.reduce((replace, includeResponse) => {
for (var obj of includeResponse.results) {
obj.__type = 'Object';
obj.className = includeResponse.className;

if(className == "_User"){
delete obj.sessionToken;
}
replace[obj.objectId] = obj;
}
return replace;
}, {})

replace[obj.objectId] = obj;
}
var resp = {
results: replacePointers(response.results, path, replace)
};
Expand Down

0 comments on commit ca7d858

Please sign in to comment.