parse-platformparse-cloud-codepfrelation

With Parse cloud code, query a users friends using PFRelation


In Parse cloud code, I need to query a list of all users in relation (pfrelation) with a given user. The Parse cloud code reference isn't very extensive.

Here is what I have...

Parse.Cloud.define("FindFriendsWithRelation", function(request, response) {
                   Parse.Cloud.useMasterKey();

                   var currentUser = request.user;

                   var relation = currentUser.relation("friendsRelation");
                   var query1 = new Parse.Query(relation);
                   query1.ascending("name");
                   query1.find({
                               success: function(results) {
                               console.log(results);
                               response.success(results);

                               },
                               error: function(error) {
                               console.log(error);
                               response.error("Could not find users.");

                               }
                               });

                   });

My error seems to be in this line

var query1 = new Parse.Query(relation);

I think I have to combine the query with the users class somehow, but I cannot figure it out.


Solution

  • Hi every relation Object has a query Method you should use it like this,

     var query1 = relation.query();
    

    you will get as return a Parse.Query object, i think that will solve your issue