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:
Diamond Lewis
2020-11-12 15:14:44 -06:00
committed by GitHub
parent a4c84c09be
commit c1971b2ab1
2 changed files with 37 additions and 9 deletions

View File

@@ -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;