fix(db-postgres): camelCase point fields (#13519)
Fixes https://github.com/payloadcms/payload/issues/13394
This commit is contained in:
@@ -791,9 +791,14 @@ export const traverseFields = ({
|
||||
} else {
|
||||
shouldSelect = true
|
||||
}
|
||||
const tableName = fieldShouldBeLocalized({ field, parentIsLocalized })
|
||||
? `${currentTableName}${adapter.localesSuffix}`
|
||||
: currentTableName
|
||||
|
||||
if (shouldSelect) {
|
||||
args.extras[name] = sql.raw(`ST_AsGeoJSON(${toSnakeCase(name)})::jsonb`).as(name)
|
||||
args.extras[name] = sql
|
||||
.raw(`ST_AsGeoJSON("${adapter.tables[tableName][name].name}")::jsonb`)
|
||||
.as(name)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ const PointFields: CollectionConfig = {
|
||||
label: 'Location',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'camelCasePoint',
|
||||
type: 'point',
|
||||
},
|
||||
{
|
||||
name: 'localized',
|
||||
type: 'point',
|
||||
|
||||
@@ -1448,6 +1448,18 @@ describe('Fields', () => {
|
||||
|
||||
expect(updatedDoc.localized).toEqual(undefined)
|
||||
})
|
||||
|
||||
it('should not error with camel case name point field', async () => {
|
||||
if (payload.db.name === 'sqlite') {
|
||||
return
|
||||
}
|
||||
|
||||
const res = await payload.create({
|
||||
collection: 'point-fields',
|
||||
data: { point, camelCasePoint: [7, -7] },
|
||||
})
|
||||
expect(res.camelCasePoint).toEqual([7, -7])
|
||||
})
|
||||
})
|
||||
|
||||
describe('checkbox', () => {
|
||||
|
||||
@@ -1294,6 +1294,11 @@ export interface PointField {
|
||||
* @maxItems 2
|
||||
*/
|
||||
point: [number, number];
|
||||
/**
|
||||
* @minItems 2
|
||||
* @maxItems 2
|
||||
*/
|
||||
camelCasePoint?: [number, number] | null;
|
||||
/**
|
||||
* @minItems 2
|
||||
* @maxItems 2
|
||||
@@ -2895,6 +2900,7 @@ export interface NumberFieldsSelect<T extends boolean = true> {
|
||||
*/
|
||||
export interface PointFieldsSelect<T extends boolean = true> {
|
||||
point?: T;
|
||||
camelCasePoint?: T;
|
||||
localized?: T;
|
||||
group?:
|
||||
| T
|
||||
|
||||
Reference in New Issue
Block a user