diff --git a/packages/nc-gui/components/virtual-cell/Link.vue b/packages/nc-gui/components/virtual-cell/Link.vue index abc6ffbd62..791de6e0a0 100644 --- a/packages/nc-gui/components/virtual-cell/Link.vue +++ b/packages/nc-gui/components/virtual-cell/Link.vue @@ -42,10 +42,6 @@ const { relatedTableMeta, loadRelatedTableMeta, relatedTableDisplayValueProp, un isNew, reloadRowTrigger.trigger, ) - - - - const relatedTableDisplayColumn = computed( () => relatedTableMeta.value?.columns?.find((c: any) => c.title === relatedTableDisplayValueProp.value) as ColumnType | undefined, diff --git a/packages/nocodb/src/helpers/columnHelpers.ts b/packages/nocodb/src/helpers/columnHelpers.ts index 0831a5adfc..77f42d23f1 100644 --- a/packages/nocodb/src/helpers/columnHelpers.ts +++ b/packages/nocodb/src/helpers/columnHelpers.ts @@ -33,13 +33,14 @@ export async function createHmAndBtColumn( fkColName?: string, virtual: BoolType = false, isSystemCol = false, - columnMeta = null + columnMeta = null, + isLinks = false, ) { // save bt column { const title = getUniqueColumnAliasName( await child.getColumns(), - type === 'bt' ? alias : `${parent.title}`, + type === 'bt' && !isLinks ? alias : `${parent.title}`, ); await Column.insert({ title, @@ -63,7 +64,7 @@ export async function createHmAndBtColumn( { const title = getUniqueColumnAliasName( await parent.getColumns(), - type === 'hm' ? alias : `${child.title} List`, + type === 'hm' && !isLinks ? alias : `${child.title} List`, ); const col = await Column.insert({ title, @@ -79,10 +80,11 @@ export async function createHmAndBtColumn( fk_index_name: fkColName, }); - if (!isSystemCol) + if (!isSystemCol && isLinks) await populateRollupForLTAR({ column: col, - columnMeta + columnMeta, + alias }); } } @@ -219,10 +221,12 @@ export const generateFkName = (parent: TableType, child: TableType) => { export async function populateRollupForLTAR({ column, - columnMeta + columnMeta, + alias }: { column: Column; columnMeta?: any; + alias?: string; }) { const model = await column.getModel(); @@ -244,7 +248,7 @@ export async function populateRollupForLTAR({ uidt: UITypes.Links, title: getUniqueColumnAliasName( await model.getColumns(), - `${relatedModel.title} Count`, + alias || `${relatedModel.title} Count`, ), fk_rollup_column_id: pkId, fk_model_id: model.id, diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index f2d4abebc5..5161bf8ba7 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -937,6 +937,7 @@ export class ColumnsService { } break; + case UITypes.Links: case UITypes.LinkToAnotherRecord: await this.createLTARColumn({ ...param, base, project }); T.emit('evt', { evt_type: 'relation:created' }); @@ -1566,6 +1567,7 @@ export class ColumnsService { const sqlMgr = await ProjectMgrv2.getSqlMgr({ id: param.base.project_id, }); + const isLinks = param.column.uidt === UITypes.Links; // if xcdb base then treat as virtual relation to avoid creating foreign key if (param.base.is_meta) { @@ -1667,6 +1669,8 @@ export class ColumnsService { foreignKeyName, (param.column as LinkToAnotherColumnReqType).virtual, param.column['meta'], + null, + isLinks, ); } else if ((param.column as LinkToAnotherColumnReqType).type === 'mm') { const aTn = `${param.project?.prefix ?? ''}_nc_m2m_${randomID()}`; @@ -1808,7 +1812,9 @@ export class ColumnsService { const col2 = await Column.insert({ title: getUniqueColumnAliasName( await parent.getColumns(), - param.column.title ?? `${child.title} List`, + isLinks + ? `${param.column.title} List` + : param.column.title ?? `${child.title} List`, ), uidt: UITypes.LinkToAnotherRecord, @@ -1833,6 +1839,7 @@ export class ColumnsService { await populateRollupForLTAR({ column: col2, columnMeta: param.column['meta'], + alias: param.column.title, }); // todo: create index for virtual relations as well