Skip to content

Add context to object save in JS SDK #730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 27, 2020
23 changes: 23 additions & 0 deletions _includes/js/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,29 @@ teamMember.save(null, { cascadeSave: false });

```

### Cloud Code context

You may pass a `context` that is accessible in Cloud Code `beforeSave` and `afterSave` triggers for that `Parse.Object`. This is useful if you want to condition certain operations in Cloud Code triggers on ephemeral information that should not be saved with the `Parse.Object` in the database. The context is ephemeral in the sense that it vanishes after the Cloud Code triggers for that particular `Parse.Object` have executed. For example:

```javascript
var TeamMember = Parse.Object.extend("TeamMember");
var teamMember = new TeamMember();
teamMember.set("team", "A");

var context = { notifyTeam: false };
await teamMember.save(null, { context: context });
```

The context is then accessible in Cloud Code:

```javascript
Parse.Cloud.afterSave("TeamMember", async (req) => {
var notifyTeam = req.context.notifyTeam;
if (notifyTeam) {
// Notify team about new member.
}
});
```

## Retrieving Objects

Expand Down