Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check if beforeSave is called for a new Parse object, or for updating an existing object?

I need to check (and take appropriate action) if an object is just being created, or an already-existing object is being updated with new values. Is there any way to check this accurately?

like image 321
Can Poyrazoğlu Avatar asked Sep 19 '14 21:09

Can Poyrazoğlu


1 Answers

Yes there is. A new object will not have an id yet, so you can check the object if it has an id.

Parse.Cloud.beforeSave("MyClass", function (request, response) {
    var object = request.object;
    if (!object.id) {
       // this is a new object
    }
});
like image 149
Tom Erik Støwer Avatar answered Dec 18 '22 06:12

Tom Erik Støwer