Ad

Parse Cloud Code Returns Pointer Instead Of Object After Save

- 1 answer

Problem:

I'm trying to return a full object, instead I keep getting a pointer back. I think it might be because I modify the object, then save, then return it in the response. How would I be able to modify, save, and return the full object and not the pointer?

Code: Only relevant code is shown:

getPicture(username, {
  success: function (pictureObject) {
    response.success(pictureObject); //Always getting pointer
  },
  error: function (error) {
    response.error(error);
  }
});

...

function getPicture(username, callback) {
    var Pictures = Parse.Object.extend("Pictures");
    var pictures = new Parse.Query(Pictures);
    pictures.equalTo("username", username);
    pictures.find({
        success: function (results) {
                var object = results[0];
                object.increment("views", 1); 
                object.save(); //I think the issue is here
                callback.success(object);
        },
        error: function (error) {
            callback.error(error);
        }
    });
}

Thank you!

Ad

Answer

You have to take the object after parse save it in the database.

try using

 object.save().then(function(newObject){
      callback.success(newObject);
 });

this will send the object after the save.

Ad
source: stackoverflow.com
Ad