diff --git a/packages/nocodb/src/models/Column.ts b/packages/nocodb/src/models/Column.ts index b22e55a922..4e80d0a839 100644 --- a/packages/nocodb/src/models/Column.ts +++ b/packages/nocodb/src/models/Column.ts @@ -10,6 +10,7 @@ import Noco from '../Noco'; import addFormulaErrorIfMissingColumn from '../helpers/addFormulaErrorIfMissingColumn'; import { NcError } from '../helpers/catchError'; import { extractProps } from '../helpers/extractProps'; +import { stringifyMetaProp } from '../utils/modelUtils'; import FormulaColumn from './FormulaColumn'; import LinkToAnotherRecordColumn from './LinkToAnotherRecordColumn'; import LookupColumn from './LookupColumn'; @@ -1207,4 +1208,29 @@ export default class Column implements ColumnType { } return fieldLengthLimit; } + + static async updateMeta( + { colId, meta }: { colId: string; meta: any }, + ncMeta = Noco.ncMeta, + ) { + // get existing cache + const key = `${CacheScope.COLUMN}:${colId}`; + const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); + if (o) { + // update meta + o.meta = meta; + // set cache + await NocoCache.set(key, o); + } + // set meta + await ncMeta.metaUpdate( + null, + null, + MetaTable.COLUMNS, + { + meta: stringifyMetaProp(meta), + }, + colId, + ); + } } diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 840cf8d159..3a5a8df4e9 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -41,10 +41,7 @@ import Noco from '../Noco'; import NcConnectionMgrv2 from '../utils/common/NcConnectionMgrv2'; import { MetaTable } from '../utils/globals'; import { MetaService } from '../meta/meta.service'; -import type { - LinkToAnotherRecordColumn, - Project, -} from '../models'; +import type { LinkToAnotherRecordColumn, Project } from '../models'; import type SqlMgrv2 from '../db/sql-mgr/v2/SqlMgrv2'; import type { ColumnReqType, @@ -124,6 +121,7 @@ export class ColumnsService { UITypes.QrCode, UITypes.Barcode, UITypes.ForeignKey, + UITypes.Links, ].includes(column.uidt) ) { if (column.uidt === colBody.uidt) { @@ -161,10 +159,18 @@ export class ColumnsService { ...column, ...colBody, }); - } else if (colBody.title !== column.title) { - await Column.updateAlias(param.columnId, { - title: colBody.title, - }); + } else { + if (colBody.title !== column.title) { + await Column.updateAlias(param.columnId, { + title: colBody.title, + }); + } + if ('meta' in colBody && column.uidt === UITypes.Links) { + await Column.updateMeta({ + colId: param.columnId, + meta: colBody.meta, + }); + } } await this.updateRollupOrLookup(colBody, column); } else { @@ -1647,7 +1653,7 @@ export class ColumnsService { (param.column as LinkToAnotherColumnReqType).title, foreignKeyName, (param.column as LinkToAnotherColumnReqType).virtual, - param.column['meta'] + param.column['meta'], ); } else if ((param.column as LinkToAnotherColumnReqType).type === 'mm') { const aTn = `${param.project?.prefix ?? ''}_nc_m2m_${randomID()}`; @@ -1809,11 +1815,11 @@ export class ColumnsService { await populateRollupForLTAR({ column: col1, - columnMeta: param.column['meta'] + columnMeta: param.column['meta'], }); await populateRollupForLTAR({ column: col2, - columnMeta: param.column['meta'] + columnMeta: param.column['meta'], }); // todo: create index for virtual relations as well