From c1ce6be9b9817d1e0081a635972311f033730f81 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 17 May 2024 17:17:57 +0100 Subject: [PATCH] Disallowing arrays for single types (attachment and user). --- packages/server/src/sdk/app/rows/utils.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/server/src/sdk/app/rows/utils.ts b/packages/server/src/sdk/app/rows/utils.ts index a9df4f89cd..777ebff655 100644 --- a/packages/server/src/sdk/app/rows/utils.ts +++ b/packages/server/src/sdk/app/rows/utils.ts @@ -14,7 +14,7 @@ import { makeExternalQuery } from "../../../integrations/base/query" import { Format } from "../../../api/controllers/view/exporters" import sdk from "../.." import { isRelationshipColumn } from "../../../db/utils" -import { SqlClient, isSQL } from "../../../integrations/utils" +import { isSQL, SqlClient } from "../../../integrations/utils" const SQL_CLIENT_SOURCE_MAP: Record = { [SourceName.POSTGRES]: SqlClient.POSTGRES, @@ -144,6 +144,10 @@ export async function validate({ throw new Error("Unable to fetch table for validation") } const errors: Record = {} + const disallowArrayTypes = [ + FieldType.ATTACHMENT_SINGLE, + FieldType.BB_REFERENCE_SINGLE, + ] for (let fieldName of Object.keys(fetchedTable.schema)) { const column = fetchedTable.schema[fieldName] const constraints = cloneDeep(column.constraints) @@ -160,6 +164,10 @@ export async function validate({ if (type === FieldType.OPTIONS && constraints?.inclusion) { constraints.inclusion.push(null as any, "") } + + if (disallowArrayTypes.includes(type) && Array.isArray(row[fieldName])) { + errors[fieldName] = `Cannot accept arrays` + } let res // Validate.js doesn't seem to handle array