aryaxt
aryaxt

Reputation: 77596

Parse - afterSave and accessing request object?

I send a request to parse that includes a Comment object that has a pointer to a User named "from".

In afterSave I need to read this and I'm having all kinds of problems. beforeSave works just fine, but I want to execute this code in afterSave;

Parse.Cloud.afterSave("Comment", function(request) {
    var userQuery = new Parse.Query("User");

    userQuery.get(request.object.get("from").id, {
        success: function(user) {

                },
                error : function(error) {
                    console.error("errrrrrrrr" + error);
                }
        });
});

Here is the log I'm seeing on parse

errrrrrrrrr [object Object]

EDIT:

I also tried

var userQuery = new Parse.Query("_User");

Upvotes: 1

Views: 1550

Answers (3)

Skytiger
Skytiger

Reputation: 1845

Slightly different approach.

This assumes that you have the comment object available right there, or at least its id.

Instead of querying the User collection, how about this:

var commentQuery = new Parse.Query("Comment");
commentQuery.include("from");
commentQuery.get(<commentId>, {
    success: function (comment)
    {
        var user = comment.get("from"); // Here you have the user object linked to the comment :)
    },
    error: function (error)
    {
        console.log("ERROR: ");
        console.log(error);
    }
});

Upvotes: 0

Luca Iaco
Luca Iaco

Reputation: 3457

Have you tried this?

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

Try to fetch the pointer directly:

var fromUserPointer = request.object.get("from");

fromUserPointer.fetch().then(function(fetchedFromUser){



},function(error){


});

Upvotes: 0

aryaxt
aryaxt

Reputation: 77596

Seems like I had to call useMasterKey, since I was fetching a user data. I'm not entirely sure about this though so I'll keep this question open.

Parse.Cloud.useMasterKey();

Upvotes: 1

Related Questions