Skip to content

Commit aa90271

Browse files
authored
fix(db-postgres): camelCase point fields (#13519)
Fixes #13394
1 parent 5e433aa commit aa90271

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

packages/drizzle/src/find/traverseFields.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,14 @@ export const traverseFields = ({
791791
} else {
792792
shouldSelect = true
793793
}
794+
const tableName = fieldShouldBeLocalized({ field, parentIsLocalized })
795+
? `${currentTableName}${adapter.localesSuffix}`
796+
: currentTableName
794797

795798
if (shouldSelect) {
796-
args.extras[name] = sql.raw(`ST_AsGeoJSON(${toSnakeCase(name)})::jsonb`).as(name)
799+
args.extras[name] = sql
800+
.raw(`ST_AsGeoJSON("${adapter.tables[tableName][name].name}")::jsonb`)
801+
.as(name)
797802
}
798803
break
799804
}

test/fields/collections/Point/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const PointFields: CollectionConfig = {
1515
label: 'Location',
1616
required: true,
1717
},
18+
{
19+
name: 'camelCasePoint',
20+
type: 'point',
21+
},
1822
{
1923
name: 'localized',
2024
type: 'point',

test/fields/int.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,18 @@ describe('Fields', () => {
14481448

14491449
expect(updatedDoc.localized).toEqual(undefined)
14501450
})
1451+
1452+
it('should not error with camel case name point field', async () => {
1453+
if (payload.db.name === 'sqlite') {
1454+
return
1455+
}
1456+
1457+
const res = await payload.create({
1458+
collection: 'point-fields',
1459+
data: { point, camelCasePoint: [7, -7] },
1460+
})
1461+
expect(res.camelCasePoint).toEqual([7, -7])
1462+
})
14511463
})
14521464

14531465
describe('checkbox', () => {

test/fields/payload-types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,11 @@ export interface PointField {
12941294
* @maxItems 2
12951295
*/
12961296
point: [number, number];
1297+
/**
1298+
* @minItems 2
1299+
* @maxItems 2
1300+
*/
1301+
camelCasePoint?: [number, number] | null;
12971302
/**
12981303
* @minItems 2
12991304
* @maxItems 2
@@ -2895,6 +2900,7 @@ export interface NumberFieldsSelect<T extends boolean = true> {
28952900
*/
28962901
export interface PointFieldsSelect<T extends boolean = true> {
28972902
point?: T;
2903+
camelCasePoint?: T;
28982904
localized?: T;
28992905
group?:
29002906
| T

0 commit comments

Comments
 (0)