diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index bd34aa95ce..596d6a74fc 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -2009,29 +2009,27 @@ export class ColumnsService { ); await sqlMgr.sqlOpPlus(source, 'tableUpdate', tableUpdateBody); - const columns: Array< - Omit & { - cn: string; - system?: boolean; - } - > = ( - await sqlClient.columnList({ - tn: table.table_name, - schema: source.getConfig()?.schema, - }) - )?.data?.list; + if (!source.isMeta()) { + const columns: Array< + Omit & { + cn: string; + system?: boolean; + } + > = ( + await sqlClient.columnList({ + tn: table.table_name, + schema: source.getConfig()?.schema, + }) + )?.data?.list; + + const insertedColumnMeta = + columns.find((c) => c.cn === colBody.column_name) || ({} as any); - const insertedColumnMeta = - columns.find((c) => c.cn === colBody.column_name) || ({} as any); + Object.assign(colBody, insertedColumnMeta); + } await Column.insert({ ...colBody, - ...insertedColumnMeta, - dtxp: [UITypes.MultiSelect, UITypes.SingleSelect].includes( - colBody.uidt as any, - ) - ? colBody.dtxp - : insertedColumnMeta.dtxp, fk_model_id: table.id, }); } diff --git a/packages/nocodb/src/services/tables.service.ts b/packages/nocodb/src/services/tables.service.ts index 40e7e190ef..f2e2846387 100644 --- a/packages/nocodb/src/services/tables.service.ts +++ b/packages/nocodb/src/services/tables.service.ts @@ -381,7 +381,7 @@ export class TablesService { validatePayload('swagger.json#/components/schemas/TableReq', param.table); const tableCreatePayLoad: Omit & { - columns: (Omit & { cn?: string })[]; + columns: (ColumnType & { cn?: string })[]; } = { ...param.table, }; @@ -548,6 +548,8 @@ export class TablesService { const uniqueColumnNameCount = {}; + mapDefaultDisplayValue(param.table.columns); + for (const column of param.table.columns) { if ( !isVirtualCol(column) || @@ -604,43 +606,36 @@ export class TablesService { tn: tableCreatePayLoad.table_name, }); - const columns: Array< + let columns: Array< Omit & { cn: string; system?: boolean; } - > = ( - await sqlMgr.sqlOpPlus(source, 'columnList', { - tn: tableCreatePayLoad.table_name, - schema: source.getConfig()?.schema, - }) - )?.data?.list; - + >; + if (!source.isMeta()) { + columns = ( + await sqlMgr.sqlOpPlus(source, 'columnList', { + tn: tableCreatePayLoad.table_name, + schema: source.getConfig()?.schema, + }) + )?.data?.list; + } const tables = await Model.list({ base_id: base.id, source_id: source.id, }); - mapDefaultDisplayValue(param.table.columns); - // todo: type correction const result = await Model.insert(base.id, source.id, { ...tableCreatePayLoad, - columns: columns.map((c, i) => { - const colMetaFromReq = param.table?.columns?.find( - (c1) => c.cn === c1.column_name, - ); + columns: tableCreatePayLoad.columns.map((c, i) => { + const colMetaFromDb = columns?.find((c1) => c.cn === c1.cn); return { - ...colMetaFromReq, - uidt: colMetaFromReq?.uidt || c.uidt || getColumnUiType(source, c), ...c, - dtxp: [UITypes.MultiSelect, UITypes.SingleSelect].includes( - colMetaFromReq.uidt as any, - ) - ? colMetaFromReq.dtxp - : c.dtxp, - title: colMetaFromReq?.title || getColumnNameAlias(c.cn, source), - column_name: c.cn, + uidt: c.uidt || getColumnUiType(source, colMetaFromDb || c), + ...(colMetaFromDb || {}), + title: c.title || getColumnNameAlias(c.cn, source), + column_name: colMetaFromDb?.cn || c.cn || c.column_name, order: i + 1, } as NormalColumnRequestType; }),