Skip to content

Save pointer to new object in beforeSave #5186

Closed
@mtrezza

Description

@mtrezza

Issue Description

It is currently not possible to reference an object in its beforeSave hook to create a new object with a pointer to it.

Steps to reproduce

Example scenario:
A user in User class should have a user profile in UserProfile class associated with it. A user profile has a pointer to the user.

It is currently only possible to create the user profile in the user's afterSave hook. But immediately after saving the user, other API calls may look for the user profile which does not exist. It is not a solution to create a user profile if it does not exists, as that can cause race conditions in which multiple user profiles are created. It is also not a solution to set the pointer to the user as unique in the mongoDB collection which prevents multiple user profile from being created but also causes data loss, because the information to update the user profile with is lost after the failed call.

Expected Results

It should be possible to create a pointer to an object in its beforeSave hook.

Actual Outcome

Trying to save a user profile causes a timeout in path="/parse/batch".

Environment Setup

  • Server

    • parse-server version: 2.8.4
    • Localhost or remote server: Heroku
  • Database

    • MongoDB version: 3.6.7
    • Localhost or remote server: mLab

Logs/Trace

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions