From 85ddeb5cd996393795514b2eeda9ec081dea015b Mon Sep 17 00:00:00 2001 From: "Raschid J.F. Rafaelly" Date: Fri, 9 Aug 2019 09:57:43 -0500 Subject: [PATCH 1/4] 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 --- _includes/js/objects.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/_includes/js/objects.md b/_includes/js/objects.md index fee0c513f..bdce11bdc 100644 --- a/_includes/js/objects.md +++ b/_includes/js/objects.md @@ -172,6 +172,34 @@ gameScore.save({ }); ``` +### Saving Nested Objects +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 really easy managing relational data as you don't have to take care of creating the objects in any specific order. + +```javascript +var Child = Parse.Object.extend("Child"); +var child = new Child(); + +var Parent = Parse.Object.extend("Parent"); +var parent = new Child(); + +parent.save({child: child}); +// Automatically the object Child is created on the server +// just before saving the Parent +``` + +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 come in handy: + +```javascript +var TeamMember = Parse.Object.extend("TeamMember"); +var = new TeamMember(); +teamMember.set('owninerAccount', ownerAccount); // Supose `ownerAccount` to have been created earlier. + +teamMember.save(null, { cascadeSave: false }); +// Will save `teamMember` wihout attempting to save or modify `ownerAccount` + +``` + + ## Retrieving Objects 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`: From f44f5f22e5f82c10308dad42caf0b8ea96cee1ee Mon Sep 17 00:00:00 2001 From: "Raschid J.F. Rafeally" Date: Fri, 9 Aug 2019 13:36:37 -0500 Subject: [PATCH 2/4] Update _includes/js/objects.md Co-Authored-By: Tom Fox --- _includes/js/objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_includes/js/objects.md b/_includes/js/objects.md index bdce11bdc..962941851 100644 --- a/_includes/js/objects.md +++ b/_includes/js/objects.md @@ -192,7 +192,7 @@ In some scenarios, you may want to prevent this default chain save. For example, ```javascript var TeamMember = Parse.Object.extend("TeamMember"); var = new TeamMember(); -teamMember.set('owninerAccount', ownerAccount); // Supose `ownerAccount` to have been created earlier. +teamMember.set('owninerAccount', ownerAccount); // Suppose `ownerAccount` has been created earlier. teamMember.save(null, { cascadeSave: false }); // Will save `teamMember` wihout attempting to save or modify `ownerAccount` From 5c4a3611f2606c6296402f9bceb16d385a919ad2 Mon Sep 17 00:00:00 2001 From: "Raschid J.F. Rafeally" Date: Fri, 9 Aug 2019 13:36:45 -0500 Subject: [PATCH 3/4] Update _includes/js/objects.md Co-Authored-By: Tom Fox --- _includes/js/objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_includes/js/objects.md b/_includes/js/objects.md index 962941851..eafb12c6c 100644 --- a/_includes/js/objects.md +++ b/_includes/js/objects.md @@ -187,7 +187,7 @@ parent.save({child: child}); // just before saving the Parent ``` -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 come in handy: +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: ```javascript var TeamMember = Parse.Object.extend("TeamMember"); From b944b623b94a8b535f4a63efa6091ac309d2d33a Mon Sep 17 00:00:00 2001 From: "Raschid J.F. Rafeally" Date: Fri, 9 Aug 2019 13:36:51 -0500 Subject: [PATCH 4/4] Update _includes/js/objects.md Co-Authored-By: Tom Fox --- _includes/js/objects.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_includes/js/objects.md b/_includes/js/objects.md index eafb12c6c..bb9c4310b 100644 --- a/_includes/js/objects.md +++ b/_includes/js/objects.md @@ -173,7 +173,7 @@ gameScore.save({ ``` ### Saving Nested Objects -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 really easy managing relational data as you don't have to take care of creating the objects in any specific order. +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. ```javascript var Child = Parse.Object.extend("Child");