Search code examples
javascriptpointersparse-platformparse-cloud-code

Basic Parse query to access a field inside a pointer object in JavaScript


I have a table called "Current1", which I am saving user's object as pointer like this:

enter image description here

When I click on this pointer I direct to _User table. Now I am trying to do very simple query. I need to access to username inside user pointer and later update something in _User table.

My problem is now to access 'username' in '_User' table by using a pointer:

var aveGame2 = Parse.Object.extend("Current1");
var query2 = new Parse.Query(aveGame2);
query2.include("user");
query2.find({
    success: function(results) {

        for (var i = 0; i < results.length; i++) 
        {
            var object = results[i];
            //....
            var user = object.get('user');

            var username = user.get('username'); //<--Error is pointing to this line

            //More operation

            if(True)//Some conditions
            {
                Parse.Cloud.useMasterKey();
                var query = new Parse.Query(Parse.User);
                query.equalTo("username", username);

                // Get the first user which matches the above constraints.
                query.first({
                    success: function(anotherUser) {

                        anotherUser.set("prize", 10);

                        // Save the user.
                        anotherUser.save(null, {
                          success: function(anotherUser) {
                          // The user was saved successfully.
                          response.success("Successfully updated user.");
                        },
                        error: function(gameScore, error) {
                           // The save failed.
                           // error is a Parse.Error with an error code and description.
                           response.error("Could not save changes to user.");
                        }
                    });
                },
             error: function(error) {
                 response.error("Could not find user.");
             }
});

Error:

[Error]: TypeError: Cannot call method 'get' of undefined
    at e.query2.find.success

Solution

  • After hours of checking each fields I realised I have not set ACL for _User table as Public read. This might help someone else.