Retrieving data using a pointer in Parse.com

891 views Asked by At

I am having a hard time doing something that should be simple. I must be missing something obvious. In Parse.com cloud code, I have a pointer (p) to an object in a Class (myClass). How can I get hold of the object in myClass, using the pointer (p)?

Searching the net makes me think I should be using fetch().

But however I tried failed. It seems like my fetch is just ignored.

I have used variations of this code pattern, all with the same failing result:

anObject.get("pointer").fetch()
{
}

for example with:

console.log("SIGNAL--BEFORE");
anObject.get("pointer").fetch({
    success: function(myObject) {
        console.log("ALL--OOKK");
    }
});
console.log("SIGNAL--AFTER");

I never see the "ALL--OOKK" in the logs. Though I can see both "SIGNAL--BEFORE" and "SIGNAL--AFTER".

I have verified that anObject.get("pointer") is a valid objectId, so the problem has to be in the way I use fetch.

2

There are 2 answers

4
iForests On

You are almost there. You need to pass a success function to the function fetch().

anObject.get("pointer").fetch({
    success: function(result) {

        // result is an ParseObject of your "pointer" class

        // If there is a column called "title" in your "pointer" class
        // you can get the data by...

        var title = result.get('title');
        response.success(title);
    },
    error: function(error) {
        console.error('Error: ' + error.code + ' - ' + error.message);
    }
});
0
bond On

You may try find() as well:

    var myClassQuery = new Parse.Query("myClass");
    myClassQuery.include("pointer"); //where "pointer" is a column name
    myClassQuery.find().then(function (results) {
        //success code
    }, function (err) {
        //error code
    });

Include multi-level pointers by just using dot(.) For e.g. myClassQuery.include("pointer1.pointer2"). Where pointer1 is column of myClass and pointer2 is column of pointer1's class.