Skip to content

Set objectId for new Parse.Objects sooner so it can be accessed in beforeSave functions #7117

@dblythy

Description

@dblythy

New Feature / Enhancement Checklist

Current Limitation

If a new object is created, it doesn't get an object ID until setRequiredFieldsIfNeeded.

This means that any Parse.Cloud.beforeSave(Parse.User triggers won't be able to any ACL work using request.object because it won't have an ID defined.

Feature / Enhancement Description

Either assign the object ID prior to the beforeSave for new objects, or run setRequiredFieldsIfNeeded before the beforeSave.

This would be a breaking change for developers who use if (!req.object.objectId) to work out if an object is new, rather than !req.object.existed().

Example Use Case

Parse.Cloud.beforeSave(Parse.User, ({object}) => {
  if (!object.existed) {
    const acl = new Parse.ACL();
    acl.setReadAccess(object.id,true);
    acl.setWriteAccess(object.id,true);
    object.setACL(acl);
  }
});

Alternatives / Workarounds

Run the code in an afterSave trigger.

Related: #701

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions