Parse.com: Find all objects belonging to a user with objectId

Viewed 24626

I have a Class in parse, say Pictures. Each of these belongs to a user. Reference to this user is stored in the Pictures table/class as a Pointer to the user.

In my cloud code I am trying to get all Pictures belonging to a user, using master key. Following is my code:

Parse.Cloud.define("getPictures", function(request, response) {

  Parse.Cloud.useMasterKey();

  var query = new Parse.Query("Pictures");

  query.equalTo("user", request.params.user);

  query.find({
    success: function(results) {

      var status = "Found " + results.length + " pictures for userId " + request.params.user;
      response.success(status);

    },

    error: function() {

      status = "No pictures exist for userId " + request.params.user; 
      response.error(status);
    }
  });
});

This code outputs that there are 0 pictures for a certain user with id 'xyz' for example. However, I can see that the user has a lot of pictures stored.

I have also verified that the problem is not with using master key, as I see in the console log that the code is being executed as master. Moreover, if I query for a picture by objectId, it does come out in the results, which means ACL is not the problem here.

I think I have to use relations/joining here, but I am not sure how to do that.

3 Answers
Related