@@ -153,12 +153,11 @@ RestWrite.prototype.runBeforeTrigger = function() {
153
153
}
154
154
155
155
let originalObject = null ;
156
- const updatedObject = triggers . inflate ( extraData , this . originalData ) ;
156
+ const updatedObject = this . buildUpdatedObject ( extraData ) ;
157
157
if ( this . query && this . query . objectId ) {
158
158
// This is an update for existing object.
159
159
originalObject = triggers . inflate ( extraData , this . originalData ) ;
160
160
}
161
- updatedObject . set ( this . sanitizedData ( ) ) ;
162
161
163
162
return Promise . resolve ( ) . then ( ( ) => {
164
163
return triggers . maybeRunTrigger ( triggers . Types . beforeSave , this . auth , updatedObject , originalObject , this . config ) ;
@@ -1068,8 +1067,7 @@ RestWrite.prototype.runAfterTrigger = function() {
1068
1067
1069
1068
// Build the inflated object, different from beforeSave, originalData is not empty
1070
1069
// since developers can change data in the beforeSave.
1071
- const updatedObject = triggers . inflate ( extraData , this . originalData ) ;
1072
- updatedObject . set ( this . sanitizedData ( ) ) ;
1070
+ const updatedObject = this . buildUpdatedObject ( extraData ) ;
1073
1071
updatedObject . _handleSaveResponse ( this . response . response , this . response . status || 200 ) ;
1074
1072
1075
1073
// Notifiy LiveQueryServer if possible
@@ -1104,6 +1102,29 @@ RestWrite.prototype.sanitizedData = function() {
1104
1102
return Parse . _decode ( undefined , data ) ;
1105
1103
}
1106
1104
1105
+ // Returns an updated copy of the object
1106
+ RestWrite . prototype . buildUpdatedObject = function ( extraData ) {
1107
+ const updatedObject = triggers . inflate ( extraData , this . originalData ) ;
1108
+ Object . keys ( this . data ) . reduce ( function ( data , key ) {
1109
+ if ( key . indexOf ( "." ) > 0 ) {
1110
+ // subdocument key with dot notation ('x.y':v => 'x':{'y':v})
1111
+ const splittedKey = key . split ( "." ) ;
1112
+ const parentProp = splittedKey [ 0 ] ;
1113
+ let parentVal = updatedObject . get ( parentProp ) ;
1114
+ if ( typeof parentVal !== 'object' ) {
1115
+ parentVal = { } ;
1116
+ }
1117
+ parentVal [ splittedKey [ 1 ] ] = data [ key ] ;
1118
+ updatedObject . set ( parentProp , parentVal ) ;
1119
+ delete data [ key ] ;
1120
+ }
1121
+ return data ;
1122
+ } , deepcopy ( this . data ) ) ;
1123
+
1124
+ updatedObject . set ( this . sanitizedData ( ) ) ;
1125
+ return updatedObject ;
1126
+ } ;
1127
+
1107
1128
RestWrite . prototype . cleanUserAuthData = function ( ) {
1108
1129
if ( this . response && this . response . response && this . className === '_User' ) {
1109
1130
const user = this . response . response ;
0 commit comments