Browse Source

refactor: use the column name with Links and treat LTAR as it is

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5848/head
Pranav C 1 year ago
parent
commit
d36d44c004
  1. 4
      packages/nc-gui/components/virtual-cell/Link.vue
  2. 18
      packages/nocodb/src/helpers/columnHelpers.ts
  3. 9
      packages/nocodb/src/services/columns.service.ts

4
packages/nc-gui/components/virtual-cell/Link.vue

@ -42,10 +42,6 @@ const { relatedTableMeta, loadRelatedTableMeta, relatedTableDisplayValueProp, un
isNew, isNew,
reloadRowTrigger.trigger, reloadRowTrigger.trigger,
) )
const relatedTableDisplayColumn = computed( const relatedTableDisplayColumn = computed(
() => () =>
relatedTableMeta.value?.columns?.find((c: any) => c.title === relatedTableDisplayValueProp.value) as ColumnType | undefined, relatedTableMeta.value?.columns?.find((c: any) => c.title === relatedTableDisplayValueProp.value) as ColumnType | undefined,

18
packages/nocodb/src/helpers/columnHelpers.ts

@ -33,13 +33,14 @@ export async function createHmAndBtColumn(
fkColName?: string, fkColName?: string,
virtual: BoolType = false, virtual: BoolType = false,
isSystemCol = false, isSystemCol = false,
columnMeta = null columnMeta = null,
isLinks = false,
) { ) {
// save bt column // save bt column
{ {
const title = getUniqueColumnAliasName( const title = getUniqueColumnAliasName(
await child.getColumns(), await child.getColumns(),
type === 'bt' ? alias : `${parent.title}`, type === 'bt' && !isLinks ? alias : `${parent.title}`,
); );
await Column.insert<LinkToAnotherRecordColumn>({ await Column.insert<LinkToAnotherRecordColumn>({
title, title,
@ -63,7 +64,7 @@ export async function createHmAndBtColumn(
{ {
const title = getUniqueColumnAliasName( const title = getUniqueColumnAliasName(
await parent.getColumns(), await parent.getColumns(),
type === 'hm' ? alias : `${child.title} List`, type === 'hm' && !isLinks ? alias : `${child.title} List`,
); );
const col = await Column.insert({ const col = await Column.insert({
title, title,
@ -79,10 +80,11 @@ export async function createHmAndBtColumn(
fk_index_name: fkColName, fk_index_name: fkColName,
}); });
if (!isSystemCol) if (!isSystemCol && isLinks)
await populateRollupForLTAR({ await populateRollupForLTAR({
column: col, column: col,
columnMeta columnMeta,
alias
}); });
} }
} }
@ -219,10 +221,12 @@ export const generateFkName = (parent: TableType, child: TableType) => {
export async function populateRollupForLTAR({ export async function populateRollupForLTAR({
column, column,
columnMeta columnMeta,
alias
}: { }: {
column: Column; column: Column;
columnMeta?: any; columnMeta?: any;
alias?: string;
}) { }) {
const model = await column.getModel(); const model = await column.getModel();
@ -244,7 +248,7 @@ export async function populateRollupForLTAR({
uidt: UITypes.Links, uidt: UITypes.Links,
title: getUniqueColumnAliasName( title: getUniqueColumnAliasName(
await model.getColumns(), await model.getColumns(),
`${relatedModel.title} Count`, alias || `${relatedModel.title} Count`,
), ),
fk_rollup_column_id: pkId, fk_rollup_column_id: pkId,
fk_model_id: model.id, fk_model_id: model.id,

9
packages/nocodb/src/services/columns.service.ts

@ -937,6 +937,7 @@ export class ColumnsService {
} }
break; break;
case UITypes.Links:
case UITypes.LinkToAnotherRecord: case UITypes.LinkToAnotherRecord:
await this.createLTARColumn({ ...param, base, project }); await this.createLTARColumn({ ...param, base, project });
T.emit('evt', { evt_type: 'relation:created' }); T.emit('evt', { evt_type: 'relation:created' });
@ -1566,6 +1567,7 @@ export class ColumnsService {
const sqlMgr = await ProjectMgrv2.getSqlMgr({ const sqlMgr = await ProjectMgrv2.getSqlMgr({
id: param.base.project_id, 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 xcdb base then treat as virtual relation to avoid creating foreign key
if (param.base.is_meta) { if (param.base.is_meta) {
@ -1667,6 +1669,8 @@ export class ColumnsService {
foreignKeyName, foreignKeyName,
(param.column as LinkToAnotherColumnReqType).virtual, (param.column as LinkToAnotherColumnReqType).virtual,
param.column['meta'], param.column['meta'],
null,
isLinks,
); );
} else if ((param.column as LinkToAnotherColumnReqType).type === 'mm') { } else if ((param.column as LinkToAnotherColumnReqType).type === 'mm') {
const aTn = `${param.project?.prefix ?? ''}_nc_m2m_${randomID()}`; const aTn = `${param.project?.prefix ?? ''}_nc_m2m_${randomID()}`;
@ -1808,7 +1812,9 @@ export class ColumnsService {
const col2 = await Column.insert({ const col2 = await Column.insert({
title: getUniqueColumnAliasName( title: getUniqueColumnAliasName(
await parent.getColumns(), await parent.getColumns(),
param.column.title ?? `${child.title} List`, isLinks
? `${param.column.title} List`
: param.column.title ?? `${child.title} List`,
), ),
uidt: UITypes.LinkToAnotherRecord, uidt: UITypes.LinkToAnotherRecord,
@ -1833,6 +1839,7 @@ export class ColumnsService {
await populateRollupForLTAR({ await populateRollupForLTAR({
column: col2, column: col2,
columnMeta: param.column['meta'], columnMeta: param.column['meta'],
alias: param.column.title,
}); });
// todo: create index for virtual relations as well // todo: create index for virtual relations as well

Loading…
Cancel
Save