Don't merge JSON fields after save() when using Postgres to keep same behaviour as MongoDB (#4808) (#4815)
This commit is contained in:
@@ -1980,4 +1980,31 @@ describe('Parse.Object testing', () => {
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
it ('Update object field should store exactly same sent object', async (done) => {
|
||||
let object = new TestObject();
|
||||
|
||||
// Set initial data
|
||||
object.set("jsonData", { a: "b" });
|
||||
object = await object.save();
|
||||
equal(object.get('jsonData'), { a: "b" });
|
||||
|
||||
// Set empty JSON
|
||||
object.set("jsonData", {});
|
||||
object = await object.save();
|
||||
equal(object.get('jsonData'), {});
|
||||
|
||||
// Set new JSON data
|
||||
object.unset('jsonData')
|
||||
object.set("jsonData", { c: "d" });
|
||||
object = await object.save();
|
||||
equal(object.get('jsonData'), { c: "d" });
|
||||
|
||||
// Fetch object from server
|
||||
object = await object.fetch()
|
||||
console.log(object.id, object.get('jsonData'))
|
||||
equal(object.get('jsonData'), { c: "d" });
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1324,7 +1324,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
|
||||
return p + ` - '$${index + 1 + i}:value'`;
|
||||
}, '');
|
||||
|
||||
updatePatterns.push(`$${index}:name = ( COALESCE($${index}:name, '{}'::jsonb) ${deletePatterns} ${incrementPatterns} || $${index + 1 + keysToDelete.length}::jsonb )`);
|
||||
updatePatterns.push(`$${index}:name = ('{}'::jsonb ${deletePatterns} ${incrementPatterns} || $${index + 1 + keysToDelete.length}::jsonb )`);
|
||||
|
||||
values.push(fieldName, ...keysToDelete, JSON.stringify(fieldValue));
|
||||
index += 2 + keysToDelete.length;
|
||||
|
||||
Reference in New Issue
Block a user