Skip to content

Commit

Permalink
fix: related geometry point with same column name fails to display (#…
Browse files Browse the repository at this point in the history
…1035)

* fix: related geometry point with same column name fails to display

* test: add tests

---------

Co-authored-by: Nicolas Moreau <nicolas.moreau76@gmail.com>
  • Loading branch information
realSpok and Nicolas Moreau authored Oct 9, 2024
1 parent 6be3d95 commit 6add1c1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/serializers/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function ResourceSerializer(
record[fieldInfo.association][fieldInfo.name] = record[fieldInfo
.association][fieldInfo.name].coordinates;
}
if (fieldInfo.name && record[fieldInfo.name]) {
if (!fieldInfo.association && fieldInfo.name && record[fieldInfo.name]) {
record[fieldInfo.name] = record[fieldInfo.name].coordinates;
}
});
Expand Down
28 changes: 27 additions & 1 deletion test/fixtures/cars-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,33 @@ module.exports = {
reference: null,
inverseOf: null,
validations: [],
}, {
},
{
field: 'coordinate',
type: 'Point',
columnName: 'coordinate',
isRequired: true,
validations: [
{
type: 'is present',
message: null,
value: null,
},
],
defaultValue: null,
isPrimaryKey: false,
isReadOnly: false,
isSortable: true,
isFilterable: true,
isVirtual: false,
description: null,
reference: null,
inverseOf: null,
relationships: null,
enums: null,
integration: null,
},
{
field: 'engine@@@horsePower',
type: 'String',
defaultValue: null,
Expand Down
23 changes: 23 additions & 0 deletions test/serializers/resource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,28 @@ describe('serializers > resource', () => {
expect(carAttributes[`engine${FLATTEN_SEPARATOR}identification${FLATTEN_SEPARATOR}manufacturer`]).toBeNull();
expect(carAttributes).not.toContainKey(`engine${FLATTEN_SEPARATOR}horsePower`);
});
it('should serialize points', async () => {
const records = [
{
_id: '5fbfb0ee67e7953f9b8414bf',
name: 'Zoey',
coordinate: {
type: 'Point',
coordinates: [
-71.060316,
48.432044,
],
},
},
];

const serialized = await getSerializer(records).perform();

expect(serialized.data[0].attributes).toMatchObject({
_id: expect.any(String),
coordinate: [-71.060316, 48.432044],
name: 'Zoey',
});
});
});
});

0 comments on commit 6add1c1

Please sign in to comment.