Parse cloud code new SDK include subclass not working

让人想犯罪 __ 提交于 2019-12-23 17:14:02

问题


I was using an old parse SDK version 1.5.0 and my function was returning with all the includes. Now I tried to use the latest SDK and the function is returning the main object only (on the gate and location I get "pointers" only.).

Here is the code:

Parse.Cloud.define("get_gates_for_user", function(request, response) {
    var userId = request.params.userId;


var gateToUserQuery = new Parse.Query("GateUserJoinTable");
gateToUserQuery.equalTo("user", {
            __type: "Pointer",
            className: "_User",
            objectId: userId
        });


gateToUserQuery.include("gate");
gateToUserQuery.include("location");

gateToUserQuery.find({
    success: function(results) {
        response.success(results);
    },
    error: function(error) {
        console.log(error.message);
        response.error(ERROR_CODE_GENERAL_ERROR);
    }
});
});

回答1:


I started working with Parse recently so I'm not very familiar with the behavioiur of old SDK versions.

Since you're in Cloud Code, however, .include() doesn't warrant a significant performance gain over .fetch(), since the code runs on their infrastructure (it's the documented way of accessing related Parse.Objects, so they should be optimizing for that anyway), so the following should work:

var _ = require('underscore');
var results;
gateToUserQuery.find().then(function (joins) {
  // add results to bigger-scoped variable
  // for access in the other function
  results = joins;

  // Promises are beautiful
  var fetchPromises = _.map(results, function (join) {
    return Parse.Promise.when([
      join.get('gate').fetch(),
      join.get('location').fetch()
    ]));
  });
  return Parse.Promise.when(fetchPromises);
}).then(function () {
  // related Pointers should be filled with data
  response.success(results);
});

I think at least in the current iteration of the SDK, include only works with Arrays instead of Pointers.



来源:https://stackoverflow.com/questions/33064173/parse-cloud-code-new-sdk-include-subclass-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!