From 0e99d04f0c05aa38670af4a606e3af39aeefd512 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 22 Jan 2024 07:33:57 +0000 Subject: [PATCH] fix: pre-populate column id --- packages/nocodb/src/models/Column.ts | 17 +++++++++++++++-- packages/nocodb/src/models/Model.ts | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/nocodb/src/models/Column.ts b/packages/nocodb/src/models/Column.ts index b97295108e..900598dcf9 100644 --- a/packages/nocodb/src/models/Column.ts +++ b/packages/nocodb/src/models/Column.ts @@ -1341,9 +1341,16 @@ export default class Column implements ColumnType { ncMeta = Noco.ncMeta, ) { const extractedColumnMetas = []; + const columns = []; // add fk_model_id for (const column of param.columns) { + // pre-populate column meta to use while inserting colOptions + const id = await ncMeta.genNanoid(MetaTable.COLUMNS); + columns.push({ + ...column, + id, + }); extractedColumnMetas.push({ ...extractProps(column as any, [ 'id', @@ -1376,16 +1383,18 @@ export default class Column implements ColumnType { 'system', 'meta', ]), + id, fk_model_id: param.fk_model_id, }); } // bulk insert columns - const columns = await ncMeta.bulkMetaInsert( + await ncMeta.bulkMetaInsert( null, null, MetaTable.COLUMNS, extractedColumnMetas, + true, ); // insert column options if any @@ -1403,7 +1412,11 @@ export default class Column implements ColumnType { const insertGroups = new Map[]>(); for (const column of columns) { - let insertArr = insertGroups.get(column.uidt=== UITypes.MultiSelect ? UITypes.SingleSelect : column.uidt ); + let insertArr = insertGroups.get( + column.uidt === UITypes.MultiSelect + ? UITypes.SingleSelect + : column.uidt, + ); if (!insertArr) { insertGroups.set(column.uidt, (insertArr = [])); } diff --git a/packages/nocodb/src/models/Model.ts b/packages/nocodb/src/models/Model.ts index 81a12c0e34..a00965d40d 100644 --- a/packages/nocodb/src/models/Model.ts +++ b/packages/nocodb/src/models/Model.ts @@ -167,7 +167,7 @@ export default class Model implements TableType { source_id: sourceId, }, { - getColumns: () => insertedColumns, + getColumns: async () => insertedColumns }, ncMeta, );