3

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);
    }
});
});
  • Maybe related? http://stackoverflow.com/questions/33059768/parse-com-javascript-sdk-using-include-but-not-working – melpomene Oct 11 '15 at 11:39
  • yes seems to be the same issue! Also I tried the code using JavaScript ( on a browser page) and I can get all the sub-classes information. – yossy roitburd Oct 11 '15 at 11:41
  • Yes, the same than my post. I don't understand why. There's a way to to do it but it comes out as a dictionary, not like `List` – Rafael Ruiz Muñoz Oct 11 '15 at 12:02

1 Answers1

0

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.

paolobueno
  • 1,678
  • 10
  • 9