user379468
user379468

Reputation: 4039

how to get the parse user from the afterSave function

How do I get the parse user in the afterSave function ?

Parse.Cloud.afterSave(Parse.User, function(request) {
    Parse.Cloud.useMasterKey();


    console.log("username: "+request.user.username);


    query = new Parse.Query(Parse.User);
    query.equalTo("username", request.user.username);
    query.first ( {
        success: function(object) {

            //object.relation("users").add(request.user);
            //object.save();
            console.log("sucesss"+ object);

        },
        error: function(error) {
            throw "Got an error " + error.code + " : " + error.message;
        }
    });

});

Upvotes: 1

Views: 912

Answers (1)

Ralphilius
Ralphilius

Reputation: 1856

To get user object that is saved, use request.object. To get the user object that made the change to User class, use request.user. In your case, use the first one.

Reference: http://www.parse.com/docs/js/api/classes/Parse.Cloud.AfterSaveRequest.html

Upvotes: 2

Related Questions