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

1

6

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?

Braided answered 19/9, 2014 at 21:47 Comment(0)
T
11

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
    }
});
Triiodomethane answered 20/9, 2014 at 7:24 Comment(1)
There's also the isNew() instance method.Fugacity

© 2022 - 2024 — McMap. All rights reserved.