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,
reloadRowTrigger.trigger,
)
const relatedTableDisplayColumn = computed(
() =>
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,
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<LinkToAnotherRecordColumn>({
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,

9
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

Loading…
Cancel
Save