Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

refactor: corrections

Pranav C890457be35b8
diff --git a/packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue b/packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue
index d221f8f4cd..c15b19a093 100644
--- a/packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue
+++ b/packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue
@@ -449,27 +449,49 @@ const handleScrollIntoView = () => {
<template>
<div class="w-full flex flex-col gap-4">
- <div class="flex flex-col gap-4">
+ <div class="flex flex-col gap-4 h-30">
<a-form-item :label="$t('labels.relationType')" class="nc-ltar-relation-type">
<a-radio-group v-model:value="linkType" name="type" :disabled="isEdit">
- <a-radio value="mm" data-testid="Many to Many">
- <span class="nc-ltar-icon nc-mm-icon">
- <GeneralIcon icon="mm_solid" />
- </span>
- {{ $t('title.manyToMany') }}
- </a-radio>
- <a-radio value="hm" data-testid="Has Many">
- <span class="nc-ltar-icon nc-hm-icon">
- <GeneralIcon icon="hm_solid" />
- </span>
- {{ $t('title.hasMany') }}
- </a-radio>
- <a-radio value="oo" data-testid="One to One">
- <span class="nc-ltar-icon nc-oo-icon">
- <GeneralIcon icon="oneToOneSolid" />
- </span>
- {{ $t('title.oneToOne') }}
- </a-radio>
+ <a-row :gutter="[16, 16]">
+ <a-radio value="mm" data-testid="Many to Many" :span="12">
+ <span class="nc-ltar-icon nc-mm-icon">
+ <GeneralIcon icon="mm_solid" />
+ </span>
+ {{ $t('title.manyToMany') }}
+ </a-radio>
+ <template v-if="vModel.uidt === UITypes.LinkToAnotherRecord">
+ <a-col :span="12">
+ <a-radio :value="RelationTypes.ONE_TO_MANY" data-testid="One to Many">
+ <span class="nc-ltar-icon nc-om-icon">
+ <GeneralIcon icon="hm_solid" />
+ </span>
+ {{ $t('title.oneToMany') }}
+ </a-radio>
+ </a-col>
+ <a-col :span="12">
+ <a-radio :value="RelationTypes.MANY_TO_ONE" data-testid="Many to One" class="nc-relation-radio">
+ <span class="nc-ltar-icon nc-mo-icon">
+ <GeneralIcon icon="bt_solid" />
+ </span>
+ {{ $t('title.manyToOne') }}
+ </a-radio>
+ </a-col>
+ </template>
+ <template v-else>
+ <a-radio value="hm" data-testid="Has Many" :span="12">
+ <span class="nc-ltar-icon nc-hm-icon">
+ <GeneralIcon icon="hm_solid" />
+ </span>
+ {{ $t('title.hasMany') }}
+ </a-radio>
+ </template>
+ <a-radio value="oo" data-testid="One to One" :span="12">
+ <span class="nc-ltar-icon nc-oo-icon">
+ <GeneralIcon icon="oneToOneSolid" />
+ </span>
+ {{ $t('title.oneToOne') }}
+ </a-radio>
+ </a-row>
</a-radio-group>
</a-form-item>
</div>
diff --git a/packages/nc-gui/composables/useLTARStore.ts b/packages/nc-gui/composables/useLTARStore.ts
index 257eefe318..de51b51e10 100644
--- a/packages/nc-gui/composables/useLTARStore.ts
+++ b/packages/nc-gui/composables/useLTARStore.ts
@@ -6,6 +6,7 @@ import {
dateFormats,
hideExtraFieldsMetaKey,
isDateOrDateTimeCol,
+ isLinkV2,
isLinksOrLTAR,
isNumericCol,
isSystemColumn,
@@ -116,6 +117,18 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
const colOptions = computed(() => column.value?.colOptions as LinkToAnotherRecordType)
+ const type = computed(() =>
+ isLinkV2(column.value) ? 'ln' : (colOptions.value?.type as RelationTypes)
+ )
+
+ const isSingleTargetRelation = computed(() => {
+ return (
+ colOptions.value?.type === RelationTypes.MANY_TO_ONE ||
+ colOptions.value?.type === RelationTypes.BELONGS_TO ||
+ colOptions.value?.type === RelationTypes.ONE_TO_ONE
+ )
+ })
+
const { sharedView } = useSharedView()
const { getViewColumns } = useSmartsheetStoreOrThrow()
@@ -521,7 +534,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
meta.value?.base_id ?? baseId,
meta.value.id,
encodeURIComponent(rowId.value),
- colOptions.value.type as RelationTypes,
+ type.value,
column?.value?.id,
{
limit: String(childrenExcludedListPagination.size),
@@ -543,7 +556,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
// compare all keys and values
childrenExcludedList.value.list.forEach((row: any, index: number) => {
const found = (
- [RelationTypes.BELONGS_TO, RelationTypes.ONE_TO_ONE].includes(colOptions.value.type)
+ isSingleTargetRelation.value
? [activeState[column.value.title]]
: activeState[column.value.title]
).find((a: any) => {
@@ -582,7 +595,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
try {
isChildrenLoading.value = true
- if ([RelationTypes.BELONGS_TO, RelationTypes.ONE_TO_ONE].includes(colOptions.value.type)) return
+ if (isSingleTargetRelation.value) return
if (!column.value) return
let offset = childrenListPagination.size * (childrenListPagination.page - 1) + childrenListOffsetCount.value
if (offset < 0 || resetOffset) {
@@ -619,7 +632,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
childrenList.value = await $api.public.dataNestedList(
sharedView.value?.uuid as string,
encodeURIComponent(rowId.value),
- colOptions.value.type as RelationTypes,
+ type.value as RelationTypes,
column.value.id,
{
limit: String(childrenListPagination.size),
@@ -638,7 +651,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
meta.value?.base_id ?? ((base?.value?.id || (sharedView.value?.view as any)?.base_id) as string),
meta.value.id,
encodeURIComponent(rowId.value),
- colOptions.value.type as RelationTypes,
+ type.value as RelationTypes,
column?.value?.id,
{
limit: String(limit ?? childrenListPagination.size),
@@ -740,7 +753,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
metaValue?.base_id ?? (base.value.id as string),
metaValue.id!,
encodeURIComponent(rowId.value),
- colOptions.value.type as RelationTypes,
+ type.value as RelationTypes,
column?.value?.id,
encodeURIComponent(getRelatedTableRowId(row) as string),
)
@@ -761,7 +774,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
}
isChildrenExcludedListLinked.value[index] = false
isChildrenListLinked.value[index] = false
- if (colOptions.value.type !== RelationTypes.BELONGS_TO && colOptions.value.type !== RelationTypes.ONE_TO_ONE) {
+ if (!isSingleTargetRelation.value) {
childrenListCount.value = childrenListCount.value - 1
}
} catch (e: any) {
@@ -811,7 +824,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
metaValue?.base_id ?? (base.value.id as string),
metaValue.id as string,
encodeURIComponent(rowId.value),
- colOptions.value.type as RelationTypes,
+ type.value as RelationTypes,
column?.value?.id,
encodeURIComponent(getRelatedTableRowId(row) as string) as string,
)
@@ -849,7 +862,7 @@ const [useProvideLTARStore, useLTARStore] = useInjectionState(
isChildrenExcludedListLinked.value[index] = true
isChildrenListLinked.value[index] = true
- if (colOptions.value.type !== RelationTypes.BELONGS_TO && colOptions.value.type !== RelationTypes.ONE_TO_ONE) {
+ if (!isSingleTargetRelation.value) {
childrenListCount.value = childrenListCount.value + 1
} else {
isChildrenExcludedListLinked.value = Array(childrenExcludedList.value?.list.length).fill(false)
diff --git a/packages/nocodb-sdk/src/lib/helperFunctions.ts b/packages/nocodb-sdk/src/lib/helperFunctions.ts
index d574886909..39b0b33a72 100644
--- a/packages/nocodb-sdk/src/lib/helperFunctions.ts
+++ b/packages/nocodb-sdk/src/lib/helperFunctions.ts
@@ -7,7 +7,7 @@ import {
IntegrationsType,
LinkToAnotherRecordType,
} from './Api';
-import { FormulaDataTypes } from './formulaHelpers';
+import { FormulaDataTypes } from './formula/enums';
import { ncIsNull, ncIsUndefined } from '~/lib/is';
// import {RelationTypes} from "./globals";
@@ -259,7 +259,6 @@ const testDataBaseNames = {
mysql: null,
[ClientType.PG]: 'postgres',
oracledb: 'xe',
- [ClientType.MSSQL]: undefined,
[ClientType.SQLITE]: 'a.sqlite',
};
@@ -326,3 +325,14 @@ export function isCrossBaseLink(col: ColumnType) {
(col.colOptions as LinkToAnotherRecordType)?.base_id
);
}
+
+export function formatBytes(bytes, decimals = 2, base = 1000) {
+ if (bytes === 0) return '0 Bytes';
+
+ const k = base;
+ const dm = Math.max(0, decimals);
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
+
+ return `${(bytes / k ** i).toFixed(dm)} ${sizes[i]}`;
+}
diff --git a/packages/nocodb/src/db/formulav2/lookup-or-ltar-builder.ts b/packages/nocodb/src/db/formulav2/lookup-or-ltar-builder.ts
index 180c8b5a05..fb7d7c0b62 100644
--- a/packages/nocodb/src/db/formulav2/lookup-or-ltar-builder.ts
+++ b/packages/nocodb/src/db/formulav2/lookup-or-ltar-builder.ts
@@ -1,6 +1,7 @@
import {
CircularRefContext,
ClientType,
+ isMMOrMMLike,
RelationTypes,
UITypes,
} from 'nocodb-sdk';
@@ -378,6 +379,7 @@ export const lookupOrLtarBuilder =
case UITypes.LinkToAnotherRecord:
{
const nestedAlias = `__nc_formula${getAliasCount()}`;
+ const isMMLike = isMMOrMMLike(lookupColumn);
const relation =
await lookupColumn.getColOptions<LinkToAnotherRecordColumn>(
context,
@@ -409,7 +411,9 @@ export const lookupOrLtarBuilder =
let cn;
- let relationType = relation.type;
+ let relationType = isMMLike
+ ? RelationTypes.MANY_TO_MANY
+ : relation.type;
if (relationType === RelationTypes.ONE_TO_ONE) {
relationType = relationCol.meta?.bt
diff --git a/packages/nocodb/src/db/genRollupSelectv2.ts b/packages/nocodb/src/db/genRollupSelectv2.ts
index 2688574aec..797fdee601 100644
--- a/packages/nocodb/src/db/genRollupSelectv2.ts
+++ b/packages/nocodb/src/db/genRollupSelectv2.ts
@@ -1,4 +1,9 @@
-import { NcDataErrorCodes, RelationTypes, UITypes } from 'nocodb-sdk';
+import {
+ isMMOrMMLike,
+ NcDataErrorCodes,
+ RelationTypes,
+ UITypes,
+} from 'nocodb-sdk';
import { CircularRefContext } from 'nocodb-sdk';
import type { IBaseModelSqlV2 } from './IBaseModelSqlV2';
import type { Knex } from 'knex';
@@ -63,6 +68,8 @@ export default async function genRollupSelectv2(param: {
const { parentContext, childContext, mmContext, refContext } =
await relationColumnOption.getParentChildContext(context);
+ const isMMLike = isMMOrMMLike(relationColumn);
+
const rollupColumn = columnOptions.getRollupColumn
? await columnOptions.getRollupColumn(refContext)
: await Column.get(refContext, {
@@ -220,7 +227,15 @@ export default async function genRollupSelectv2(param: {
profiler.log('applyFunction done');
};
- switch (relationColumnOption.type) {
+ const relationType = isMMLike
+ ? RelationTypes.MANY_TO_MANY
+ : relationColumnOption.type === RelationTypes.ONE_TO_ONE
+ ? relationColumn.meta?.bt
+ ? 'bt'
+ : 'hm'
+ : relationColumnOption.type;
+
+ switch (relationType) {
case RelationTypes.HAS_MANY: {
profiler.log('Relation: ' + relationColumnOption.type);
const queryBuilder: any = knex(
@@ -255,39 +270,6 @@ export default async function genRollupSelectv2(param: {
};
}
- case RelationTypes.ONE_TO_ONE: {
- profiler.log('Relation: ' + relationColumnOption.type);
- const qb = knex(
- knex.raw(`?? as ??`, [
- childBaseModel.getTnPath(childModel?.table_name),
- refTableAlias,
- ]),
- ).where(
- knex.ref(
- `${alias || parentBaseModel.getTnPath(parentModel.table_name)}.${
- parentCol.column_name
- }`,
- ),
- '=',
- knex.ref(`${refTableAlias}.${childCol.column_name}`),
- );
-
- await extractLinkRelFiltersAndApply({
- qb,
- column,
- alias: refTableAlias,
- table: childBaseModel.model,
- baseModel: childBaseModel,
- context: childBaseModel.context,
- });
-
- await applyFunction(qb);
- profiler.end();
- return {
- builder: qb,
- };
- }
-
case RelationTypes.MANY_TO_MANY: {
profiler.log('Relation: ' + relationColumnOption.type);
const mmModel = await relationColumnOption.getMMModel(mmContext);
diff --git a/packages/nocodb/src/db/generateLookupSelectQuery.ts b/packages/nocodb/src/db/generateLookupSelectQuery.ts
index 5073145e5b..1f36e1ffd3 100644
--- a/packages/nocodb/src/db/generateLookupSelectQuery.ts
+++ b/packages/nocodb/src/db/generateLookupSelectQuery.ts
@@ -1,4 +1,4 @@
-import { RelationTypes, UITypes } from 'nocodb-sdk';
+import { isMMOrMMLike, RelationTypes, UITypes } from 'nocodb-sdk';
import type { Knex } from 'knex';
import type { IBaseModelSqlV2 } from '~/db/IBaseModelSqlV2';
import type { QueryWithCte } from '~/helpers/dbHelpers';
@@ -73,7 +73,10 @@ export default async function generateLookupSelectQuery({
if (column.uidt === UITypes.Lookup) {
lookupColOpt = await column.getColOptions<LookupColumn>(context);
- } else if (column.uidt !== UITypes.LinkToAnotherRecord) {
+ } else if (
+ column.uidt !== UITypes.LinkToAnotherRecord &&
+ column.uidt !== UITypes.Links
+ ) {
NcError.get(context).badRequest('Invalid field type');
}
@@ -86,6 +89,8 @@ export default async function generateLookupSelectQuery({
const relation =
await relationCol.getColOptions<LinkToAnotherRecordColumn>(context);
+ const isMMLike = isMMOrMMLike(column);
+
const {
parentContext,
childContext,
@@ -102,7 +107,7 @@ export default async function generateLookupSelectQuery({
: RelationTypes.HAS_MANY;
}
- if (relationType === RelationTypes.BELONGS_TO) {
+ if (relationType === RelationTypes.BELONGS_TO && !isMMLike) {
const childColumn = await relation.getChildColumn(context);
const parentColumn = await relation.getParentColumn(context);
const childModel = await childColumn.getModel(childContext);
@@ -133,7 +138,7 @@ export default async function generateLookupSelectQuery({
}`,
]),
);
- } else if (relationType === RelationTypes.HAS_MANY) {
+ } else if (relationType === RelationTypes.HAS_MANY && !isMMLike) {
isBtLookup = false;
const childColumn = await relation.getChildColumn(context);
const parentColumn = await relation.getParentColumn(context);
@@ -165,7 +170,7 @@ export default async function generateLookupSelectQuery({
}.${parentColumn.column_name}`,
]),
);
- } else if (relationType === RelationTypes.MANY_TO_MANY) {
+ } else if (relationType === RelationTypes.MANY_TO_MANY || isMMLike) {
isBtLookup = false;
const childColumn = await relation.getChildColumn(context);
const parentColumn = await relation.getParentColumn(context);
@@ -258,7 +263,9 @@ export default async function generateLookupSelectQuery({
const relation =
await relationCol.getColOptions<LinkToAnotherRecordColumn>(context);
- let relationType = relation.type;
+ let relationType = isMMOrMMLike(relationCol)
+ ? RelationTypes.MANY_TO_MANY
+ : relation.type;
if (relationType === RelationTypes.ONE_TO_ONE) {
relationType = relationCol.meta?.bt
diff --git a/packages/nocodb/src/db/relation-manager.ts b/packages/nocodb/src/db/relation-manager.ts
index 15ad8ec44c..f1961fda61 100644
--- a/packages/nocodb/src/db/relation-manager.ts
+++ b/packages/nocodb/src/db/relation-manager.ts
@@ -425,20 +425,16 @@ export class RelationManager {
model: parentTable,
rowIds: [parentId],
cookie: req,
- updatedColIds: [refTableLinkColumnId],
+ updatedColIds: [],
});
- await parentBaseModel.broadcastLinkUpdates([parentId]);
-
await childBaseModel.updateLastModified({
baseModel: childBaseModel,
model: childTable,
rowIds: [childId],
cookie: req,
- updatedColIds: [column.id],
+ updatedColIds: [],
});
-
- await childBaseModel.broadcastLinkUpdates([childId]);
}
break;
case RelationTypes.HAS_MANY:
@@ -481,7 +477,7 @@ export class RelationManager {
model: parentTable,
rowIds: [oldRowId],
cookie: req,
- updatedColIds: [column.id],
+ updatedColIds: [],
});
}
@@ -509,20 +505,16 @@ export class RelationManager {
model: childTable,
rowIds: [childId],
cookie: req,
- updatedColIds: [refTableLinkColumnId],
+ updatedColIds: [],
});
- await childBaseModel.broadcastLinkUpdates([childId]);
-
await parentBaseModel.updateLastModified({
baseModel: parentBaseModel,
model: parentTable,
rowIds: [parentId],
cookie: req,
- updatedColIds: [column.id],
+ updatedColIds: [],
});
-
- await parentBaseModel.broadcastLinkUpdates([parentId]);
}
break;
case RelationTypes.BELONGS_TO:
@@ -565,14 +557,7 @@ export class RelationManager {
model: parentTable,
rowIds: [oldParentRowId],
cookie: req,
- updatedColIds: [
- (
- await extractCorrespondingLinkColumn(childBaseModel.context, {
- ltarColumn: column,
- referencedTable: parentTable,
- })
- )?.id,
- ],
+ updatedColIds: [],
});
}
@@ -600,20 +585,16 @@ export class RelationManager {
model: childTable,
rowIds: [childId],
cookie: req,
- updatedColIds: [column.id],
+ updatedColIds: [],
});
- await childBaseModel.broadcastLinkUpdates([childId]);
-
await parentBaseModel.updateLastModified({
baseModel: parentBaseModel,
model: parentTable,
rowIds: [parentId],
cookie: req,
- updatedColIds: [refTableLinkColumnId],
+ updatedColIds: [],
});
-
- await parentBaseModel.broadcastLinkUpdates([parentId]);
}
break;
case RelationTypes.ONE_TO_ONE:
@@ -660,7 +641,7 @@ export class RelationManager {
model: childTable,
rowIds: [oldChildRowId],
cookie: req,
- updatedColIds: [column.id],
+ updatedColIds: [],
});
}
}
@@ -703,7 +684,7 @@ export class RelationManager {
model: parentTable,
rowIds: [oldRowId],
cookie: req,
- updatedColIds: [refTableLinkColumnId],
+ updatedColIds: [],
});
}
// todo: unlink if it's already mapped
@@ -749,20 +730,16 @@ export class RelationManager {
model: childTable,
rowIds: [childId],
cookie: req,
- updatedColIds: [column.meta?.bt ? column.id : refTableLinkColumnId],
+ updatedColIds: [],
});
- await childBaseModel.broadcastLinkUpdates([childId]);
-
await parentBaseModel.updateLastModified({
baseModel: parentBaseModel,
model: parentTable,
rowIds: parentId,
cookie: req,
- updatedColIds: [column.meta?.bt ? refTableLinkColumnId : column.id],
+ updatedColIds: [],
});
-
- await parentBaseModel.broadcastLinkUpdates([parentId]);
}
break;
}
@@ -860,27 +837,16 @@ export class RelationManager {
model: parentTable,
rowIds: [parentId],
cookie: req,
- updatedColIds: [
- (
- await extractCorrespondingLinkColumn(childBaseModel.context, {
- ltarColumn: this.relationContext.relationColumn,
- referencedTable: parentTable,
- })
- )?.id,
- ],
+ updatedColIds: [],
});
- await parentBaseModel.broadcastLinkUpdates([parentId]);
-
await childBaseModel.updateLastModified({
baseModel: childBaseModel,
model: childTable,
rowIds: [childId],
cookie: req,
- updatedColIds: [colOptions.fk_column_id],
+ updatedColIds: [],
});
-
- await childBaseModel.broadcastLinkUpdates([childId]);
}
break;
case RelationTypes.HAS_MANY:
@@ -904,27 +870,16 @@ export class RelationManager {
model: childTable,
rowIds: [childId],
cookie: req,
- updatedColIds: [colOptions.fk_column_id],
+ updatedColIds: [],
});
- await childBaseModel.broadcastLinkUpdates([childId]);
-
await parentBaseModel.updateLastModified({
baseModel: parentBaseModel,
model: parentTable,
rowIds: [parentId],
cookie: req,
- updatedColIds: [
- (
- await extractCorrespondingLinkColumn(childBaseModel.context, {
- ltarColumn: this.relationContext.relationColumn,
- referencedTable: parentTable,
- })
- )?.id,
- ],
+ updatedColIds: [],
});
-
- await parentBaseModel.broadcastLinkUpdates([parentId]);
}
break;
case RelationTypes.BELONGS_TO:
@@ -949,27 +904,16 @@ export class RelationManager {
model: childTable,
rowIds: [childId],
cookie: req,
- updatedColIds: [column.id],
+ updatedColIds: [],
});
- await childBaseModel.broadcastLinkUpdates([childId]);
-
await parentBaseModel.updateLastModified({
baseModel: parentBaseModel,
model: parentTable,
rowIds: [parentId],
cookie: req,
- updatedColIds: [
- (
- await extractCorrespondingLinkColumn(childBaseModel.context, {
- ltarColumn: this.relationContext.relationColumn,
- referencedTable: parentTable,
- })
- )?.id,
- ],
+ updatedColIds: [],
});
-
- await parentBaseModel.broadcastLinkUpdates([parentId]);
}
break;
case RelationTypes.ONE_TO_ONE:
@@ -988,26 +932,16 @@ export class RelationManager {
model: childTable,
rowIds: [childId],
cookie: req,
- updatedColIds: [colOptions.fk_column_id],
+ updatedColIds: [],
});
- await childBaseModel.broadcastLinkUpdates([childId]);
-
await parentBaseModel.updateLastModified({
baseModel: parentBaseModel,
model: parentTable,
rowIds: [parentId],
cookie: req,
- updatedColIds: [
- (
- await extractCorrespondingLinkColumn(childBaseModel.context, {
- ltarColumn: this.relationContext.relationColumn,
- referencedTable: parentTable,
- })
- )?.id,
- ],
+ updatedColIds: [],
});
- await parentBaseModel.broadcastLinkUpdates([parentId]);
}
break;
}
diff --git a/packages/nocodb/src/db/sortV2.ts b/packages/nocodb/src/db/sortV2.ts
index 5ba6db1205..d51acdda0b 100644
--- a/packages/nocodb/src/db/sortV2.ts
+++ b/packages/nocodb/src/db/sortV2.ts
@@ -108,6 +108,7 @@ export default async function sortV2(
break;
case UITypes.Lookup:
case UITypes.LinkToAnotherRecord:
+ case UITypes.Links:
{
const rootAlias = alias;
{
diff --git a/packages/nocodb/src/models/LinkToAnotherRecordColumn.ts b/packages/nocodb/src/models/LinkToAnotherRecordColumn.ts
index 732994460b..b0d049222c 100644
--- a/packages/nocodb/src/models/LinkToAnotherRecordColumn.ts
+++ b/packages/nocodb/src/models/LinkToAnotherRecordColumn.ts
@@ -200,6 +200,8 @@ export default class LinkToAnotherRecordColumn {
if (insertObj.version === undefined) {
insertObj.version = 2;
}
+console.log(new Error('test'))
+ console.log('Inserting LinkToAnotherRecordColumn with data:', insertObj);
await ncMeta.metaInsert2(
context.workspace_id,
diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts
index da3743ef16..c5c00d93ea 100644
--- a/packages/nocodb/src/services/columns.service.ts
+++ b/packages/nocodb/src/services/columns.service.ts
@@ -67,6 +67,8 @@ import {
deleteColumnSystemPropsFromRequest,
generateFkName,
getMMColumnNames,
+ getRevType,
+ getTargetTableRelColumn,
sanitizeColumnName,
validateLookupPayload,
validatePayload,
@@ -3776,7 +3778,7 @@ export class ColumnsService implements IColumnsService {
ncMeta,
);
if (
- colOpt.type === 'mm' &&
+ isMMOrMMLike(c) &&
colOpt.fk_parent_column_id === childColumn.id &&
colOpt.fk_child_column_id === parentColumn.id &&
colOpt.fk_mm_model_id === relationColOpt.fk_mm_model_id &&
@@ -3980,7 +3982,7 @@ export class ColumnsService implements IColumnsService {
ncMeta,
);
if (listRanges?.length) {
- NcError.get(context).badRequest(
+ NcError.badRequest(
`The column '${column.title}' is being used in Calendar View. Please update Calendar View first.`,
);
}
@@ -4604,6 +4606,8 @@ export class ColumnsService implements IColumnsService {
// version 1 is deprecated and will be removed in future
const isMMLike = (param.column as any).version !== LinksVersion.V1;
+ console.log({ isMMLike });
+
// get table and refTable models
const table = await Model.getWithInfo(context, {
id: (param.column as LinkToAnotherColumnReqType).parentId,
@@ -4669,8 +4673,9 @@ export class ColumnsService implements IColumnsService {
}
if (
- (param.column as LinkToAnotherColumnReqType).type === 'hm' ||
- (param.column as LinkToAnotherColumnReqType).type === 'bt'
+ ((param.column as LinkToAnotherColumnReqType).type === 'hm' ||
+ (param.column as LinkToAnotherColumnReqType).type === 'bt') &&
+ !isMMLike
) {
// populate fk column name
const fkColName = getUniqueColumnName(
@@ -4779,7 +4784,10 @@ export class ColumnsService implements IColumnsService {
undefined,
param.columnWebhookManager,
);
- } else if ((param.column as LinkToAnotherColumnReqType).type === 'oo') {
+ } else if (
+ !isMMLike &&
+ (param.column as LinkToAnotherColumnReqType).type === 'oo'
+ ) {
// populate fk column name
const fkColName = getUniqueColumnName(
await refTable.getColumns(refContext),
@@ -4886,7 +4894,10 @@ export class ColumnsService implements IColumnsService {
undefined,
param.columnWebhookManager,
);
- } else if ((param.column as LinkToAnotherColumnReqType).type === 'mm') {
+ } else if (
+ isMMLike ||
+ (param.column as LinkToAnotherColumnReqType).type === 'mm'
+ ) {
const aTn = await getJunctionTableName(param, table, refTable);
const aTnAlias = aTn;
@@ -4989,6 +5000,7 @@ export class ColumnsService implements IColumnsService {
(c) => c.column_name === refColumnName,
);
+ // todo: skip hm and bt if new type
await createHmAndBtColumn(
context,
param.req,
@@ -5059,6 +5071,11 @@ export class ColumnsService implements IColumnsService {
};
}
+ const revType = getRevType(
+ (param.column as Pick<LinkToAnotherColumnReqType, 'type'>)
+ .type as RelationTypes,
+ );
+
savedColumn = await Column.insert(context, {
title: getUniqueColumnAliasName(
await table.getColumns(context),
@@ -5066,7 +5083,7 @@ export class ColumnsService implements IColumnsService {
),
uidt: isLinks ? UITypes.Links : UITypes.LinkToAnotherRecord,
- type: 'mm',
+ type: (param.column as Pick<LinkToAnotherColumnReqType, 'type'>).type,
fk_model_id: table.id,
@@ -5103,7 +5120,7 @@ export class ColumnsService implements IColumnsService {
pluralize(table.title),
),
uidt: isLinks ? UITypes.Links : UITypes.LinkToAnotherRecord,
- type: 'mm',
+ type: revType,
// ref_db_alias
fk_model_id: refTable.id,