Skip to content

Commit 7b3da8b

Browse files
authored
PG: Fix updating numeric array (#5251)
* PG: Fix updating numeric array * lint
1 parent c762ee4 commit 7b3da8b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

spec/ParseQuery.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -4566,4 +4566,27 @@ describe('Parse.Query testing', () => {
45664566
result = await query.get(object.id);
45674567
equal(result.get('objectField'), { bar: true, baz: 50 });
45684568
});
4569+
4570+
it('can update numeric array', async () => {
4571+
const data1 = [0, 1.1, 1, -2, 3];
4572+
const data2 = [0, 1.1, 1, -2, 3, 4];
4573+
const obj1 = new TestObject();
4574+
obj1.set('array', data1);
4575+
await obj1.save();
4576+
equal(obj1.get('array'), data1);
4577+
4578+
const query = new Parse.Query(TestObject);
4579+
query.equalTo('objectId', obj1.id);
4580+
4581+
const result = await query.first();
4582+
equal(result.get('array'), data1);
4583+
4584+
result.set('array', data2);
4585+
equal(result.get('array'), data2);
4586+
await result.save();
4587+
equal(result.get('array'), data2);
4588+
4589+
const results = await query.find();
4590+
equal(results[0].get('array'), data2);
4591+
});
45694592
});

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

+4
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,10 @@ export class PostgresStorageAdapter implements StorageAdapter {
16571657
type = 'json';
16581658
break;
16591659
}
1660+
if (typeof elt == 'number') {
1661+
type = 'numeric';
1662+
break;
1663+
}
16601664
}
16611665
updatePatterns.push(
16621666
`$${index}:name = array_to_json($${index + 1}::${type}[])::jsonb`

0 commit comments

Comments
 (0)