Skip to content Skip to sidebar Skip to footer

Define Mutual Relation Between Two User With Parse Javascript

I would like to set a simple relation between the current user and another user (userB). I can create the sampleRelation, and current user shown up at userB's sampleRelation column

Solution 1:

You aren't changing the currentUser so calling currentUser.save() will not do anything.

Also when getting an existing user you should do the following:

Parse.Cloud.define('editUser', function(request, response) {
    Parse.Cloud.useMasterKey();

    var userQuery = newParse.Query(Parse.User);

    userQuery.get(request.params.userId)
    .then(function (user) {
        var relation = user.relation("sampleRelation");
        relation.add(request.user);
        // chain the promisereturn user.save();
    }).then(function (user) {
        var currentUser = request.user;
        var relation = currentUser.relation("sampleRelation");
        relation.add(user);
        // chain the new promisereturn currentUser.save();
    }).then(function () {
        response.success();
    }, function (error) {
        response.error(error);
    });
});

Post a Comment for "Define Mutual Relation Between Two User With Parse Javascript"