diff --git a/spec/ParseGeoPoint.spec.js b/spec/ParseGeoPoint.spec.js index 385609c1..3b57412f 100644 --- a/spec/ParseGeoPoint.spec.js +++ b/spec/ParseGeoPoint.spec.js @@ -771,4 +771,24 @@ describe('Parse.GeoPoint testing', () => { equal(count, 2); }); + + it('fails to fetch geopoints that are specifically not at (0,0)', async () => { + const tmp = new TestObject({ + location: new Parse.GeoPoint({ latitude: 0, longitude: 0 }), + }); + const tmp2 = new TestObject({ + location: new Parse.GeoPoint({ + latitude: 49.2577142, + longitude: -123.1941149, + }), + }); + await Parse.Object.saveAll([tmp, tmp2]); + const query = new Parse.Query(TestObject); + query.notEqualTo( + 'location', + new Parse.GeoPoint({ latitude: 0, longitude: 0 }) + ); + const results = await query.find(); + expect(results.length).toEqual(1); + }); }); diff --git a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js index 70df7d81..de9eb9ca 100644 --- a/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js +++ b/src/Adapters/Storage/Postgres/PostgresStorageAdapter.js @@ -360,15 +360,27 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => { continue; } else { // if not null, we need to manually exclude null - patterns.push( - `($${index}:name <> $${index + 1} OR $${index}:name IS NULL)` - ); + if (fieldValue.$ne.__type === 'GeoPoint') { + patterns.push( + `($${index}:name <> POINT($${index + 1}, $${index + + 2}) OR $${index}:name IS NULL)` + ); + } else { + patterns.push( + `($${index}:name <> $${index + 1} OR $${index}:name IS NULL)` + ); + } } } - - // TODO: support arrays - values.push(fieldName, fieldValue.$ne); - index += 2; + if (fieldValue.$ne.__type === 'GeoPoint') { + const point = fieldValue.$ne; + values.push(fieldName, point.longitude, point.latitude); + index += 3; + } else { + // TODO: support arrays + values.push(fieldName, fieldValue.$ne); + index += 2; + } } if (fieldValue.$eq !== undefined) { if (fieldValue.$eq === null) { @@ -730,15 +742,7 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => { } if (fieldValue.__type === 'GeoPoint') { - patterns.push( - '$' + - index + - ':name ~= POINT($' + - (index + 1) + - ', $' + - (index + 2) + - ')' - ); + patterns.push(`$${index}:name ~= POINT($${index + 1}, $${index + 2})`); values.push(fieldName, fieldValue.longitude, fieldValue.latitude); index += 3; }