Skip to content

Commit e129790

Browse files
RaschidJFRTomWFox
andcommitted
Add cascadeSave option in ParseObject to JS docs (#664)
* Add `cascadeSave` option in ParseObject to JS docs I thought it was worth adding a whole sub section about saving nested objects. Updating docs according to feature added in #881 * Update _includes/js/objects.md Co-Authored-By: Tom Fox <[email protected]> * Update _includes/js/objects.md Co-Authored-By: Tom Fox <[email protected]> * Update _includes/js/objects.md Co-Authored-By: Tom Fox <[email protected]>
1 parent c3c825d commit e129790

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

_includes/js/objects.md

+28
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,34 @@ gameScore.save({
172172
});
173173
```
174174

175+
### Saving Nested Objects
176+
You may add a `Parse.Object` as the value of a property in another `Parse.Object`. By default, when you call `save()` on the parent object, all nested objects will be created and/or saved as well in a batch operation. This feature makes it really easy to manage relational data as you don't have to take care of creating the objects in any specific order.
177+
178+
```javascript
179+
var Child = Parse.Object.extend("Child");
180+
var child = new Child();
181+
182+
var Parent = Parse.Object.extend("Parent");
183+
var parent = new Child();
184+
185+
parent.save({child: child});
186+
// Automatically the object Child is created on the server
187+
// just before saving the Parent
188+
```
189+
190+
In some scenarios, you may want to prevent this default chain save. For example, when saving a team member's profile that points to an account owned by another user to which you don't have write access. In this case, setting the option `cascadeSave` to `false` may be useful:
191+
192+
```javascript
193+
var TeamMember = Parse.Object.extend("TeamMember");
194+
var = new TeamMember();
195+
teamMember.set('owninerAccount', ownerAccount); // Suppose `ownerAccount` has been created earlier.
196+
197+
teamMember.save(null, { cascadeSave: false });
198+
// Will save `teamMember` wihout attempting to save or modify `ownerAccount`
199+
200+
```
201+
202+
175203
## Retrieving Objects
176204

177205
Saving data to the cloud is fun, but it's even more fun to get that data out again. If the `Parse.Object` has been uploaded to the server, you can use the `objectId` to get it using a `Parse.Query`:

0 commit comments

Comments
 (0)