fix(beforeSave/afterSave): Return value instead of Parse.Op for nested fields (#7005)
* fix(beforeSave): Return value instead of Parse.Op * afterSave test * Improve Tests * Fixed postgres test by saveArgumentsByValue
This commit is contained in:
@@ -1558,15 +1558,19 @@ RestWrite.prototype.buildUpdatedObject = function (extraData) {
|
||||
const updatedObject = triggers.inflate(extraData, this.originalData);
|
||||
Object.keys(this.data).reduce(function (data, key) {
|
||||
if (key.indexOf('.') > 0) {
|
||||
// subdocument key with dot notation ('x.y':v => 'x':{'y':v})
|
||||
const splittedKey = key.split('.');
|
||||
const parentProp = splittedKey[0];
|
||||
let parentVal = updatedObject.get(parentProp);
|
||||
if (typeof parentVal !== 'object') {
|
||||
parentVal = {};
|
||||
if (typeof data[key].__op === 'string') {
|
||||
updatedObject.set(key, data[key]);
|
||||
} else {
|
||||
// subdocument key with dot notation { 'x.y': v } => { 'x': { 'y' : v } })
|
||||
const splittedKey = key.split('.');
|
||||
const parentProp = splittedKey[0];
|
||||
let parentVal = updatedObject.get(parentProp);
|
||||
if (typeof parentVal !== 'object') {
|
||||
parentVal = {};
|
||||
}
|
||||
parentVal[splittedKey[1]] = data[key];
|
||||
updatedObject.set(parentProp, parentVal);
|
||||
}
|
||||
parentVal[splittedKey[1]] = data[key];
|
||||
updatedObject.set(parentProp, parentVal);
|
||||
delete data[key];
|
||||
}
|
||||
return data;
|
||||
|
||||
Reference in New Issue
Block a user