I have a Cloud Code function that queries some data and returns it separated into groups. For each record on these groups, I need to also get information of a column which is a pointer. My cloud code is:
var queryAuctionParticipant = new Parse.Query('AuctionParticipant');
queryAuctionParticipant.equalTo('userId', request.user);
queryAuctionParticipant.include('auctionId');
queryAuctionParticipant.include('auctionId.creatorId');
queryAuctionParticipant.findAll({
success: function(resultAuctionParticipant) {
var grouped = {
upcoming : [],
previous : [],
running : [],
};
for (var i=0; i<resultAuctionParticipant.length; i++) {
var obj = resultAuctionParticipant[i];
var auctionId = obj.get('auctionId');
if (obj.get('auctionId').get('startsAt') > now) {
grouped.upcoming.push(auctionId);
}
else if (obj.get('auctionId').get('endsAt') < now) {
grouped.previous.push(auctionId);
}
else {
grouped.running.push(auctionId);
}
}
response.success(grouped);
},
error: function(error) {
response.error(error, error.code);
}
});
Everything fine until here. If I try to console.log
the .get('auctionId').get('creatorId')
of any of the records in the Cloud Code function, all the data is logged perfectly, no problem.
However, on the result of my callFunctionInBackground
, the creatorId
column is converted to a PFUser
instance (correct) but the instance is empty, none of the columns are present.
It seems that Parse's SDK isn't parsing the result from JSON to PFObject/PFUser in a very deep level. It means if I have many pointers inside pointers, it won't retrieve the data, even using Parse's mechanism for including keys and/or pointers.
Any thoughts?
Thanks!
Had a similar problem some time ago in CloudCode, where somehow all the fields where emptied upon request.
It turned out to be a bug in Parse's newest Javascript SDK. Please have a look at your CloudCode folder - it should contain a global.json file where you can specify the JS SDK version. By default, the version states "latest", change it to "1.4.2" and upload your cloud code folder again.
In case the global.json file is missing in your cloud code folder, please have a look at the above mentioned thread, where I described how to create it manually.
Hope this works for you!