Mr T
Mr T

Reputation: 1000

Parse Server Query objectId

I'm using the below query in my web app using the Parse Server Javascript SDK. The console log is providing me with a display of the pulled information as expected, except for objectId that displays "undefined".

var query = new Parse.Query("myClass");
query.include("product");
query.find({

    success: function (results) {

        $scope.items = [];

        for (i = 0; i < results.length; i++) {

            var p = results[i].get("product");

            var item = {
                id: results[i].get("objectId"),
                barcode: p.get("barcode"),
                productName: p.get("name"),
                imageUrl: p.get("image"),
                desiredStock: results[i].get("desiredStock"),
            }

            $scope.items[$scope.items.length] = item;
            console.log(item);

        }

        $scope.$apply();
    },
    error: function (error) {
        console.log("Query Error: " + error.message);
    }
})

How do I go about obtaining the objectId into item.id?

Upvotes: 0

Views: 1256

Answers (2)

Julien Kode
Julien Kode

Reputation: 5479

You can write:

results[i].id

That's the best way to get the objectId with the Parse JS SDK

Upvotes: 1

Mr T
Mr T

Reputation: 1000

I've figured this out. The problematic line:

id: results[i].get("objectId"),

works with this command:

id: results[i]._getId(),

Upvotes: 1

Related Questions