diff --git a/spec/ParseObject.spec.js b/spec/ParseObject.spec.js index aedf251118..954d21a6f4 100644 --- a/spec/ParseObject.spec.js +++ b/spec/ParseObject.spec.js @@ -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(); + }); }); diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index 540516d37d..0b9ed5ec06 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -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;