π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix: normalize HM/BT to OM/MO in MM-like path, OO always LinkToAnotherRecord
Pranav4e99eb780bd0
diff --git a/packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue b/packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vueindex 474c12b79e..032607ae40 100644--- a/packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue+++ b/packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue@@ -229,14 +229,17 @@ const isLinks = computed(() => vModel.value.uidt === UITypes.Links && vModel.valconst isLtarV2Enabled = computed(() => isFeatureEnabled(FEATURE_FLAG.LTAR_V2))-// Set version based on feature flag and relation type+// Set version based on feature flag and uidt+// Links (V1 UI) always sends version=1; LinkToAnotherRecord (V2 UI) sends version=2watch(- [() => vModel.value.type, isLtarV2Enabled],+ [() => vModel.value.type, () => vModel.value.uidt, isLtarV2Enabled],() => {if (isEdit.value) return- if (isLtarV2Enabled.value) {+ if (isLtarV2Enabled.value && vModel.value.uidt === UITypes.LinkToAnotherRecord) {vModel.value.version = LinksVersion.V2+ } else if (vModel.value.uidt === UITypes.Links) {+ vModel.value.version = LinksVersion.V1} else {delete vModel.value.version}diff --git a/packages/nocodb/src/models/Column.ts b/packages/nocodb/src/models/Column.tsindex a9101b0678..375d4c4b49 100644--- a/packages/nocodb/src/models/Column.ts+++ b/packages/nocodb/src/models/Column.ts@@ -343,14 +343,14 @@ export default class Column<T = any> implements ColumnType {}case UITypes.Links:case UITypes.LinkToAnotherRecord: {- // V1 for hm/bt/oo without junction table (always V1, not overridable)- // If junction table exists (fk_mm_model_id), use caller version or default V2+ // V1 heuristic: hm/bt/oo without junction table are V1+ // V2 types (om, mo) or anything with junction table uses caller version or defaults to V2const isV1Heuristic =!column.fk_mm_model_id &&([RelationTypes.HAS_MANY, RelationTypes.BELONGS_TO].includes(column.type,) ||- column.type === RelationTypes.ONE_TO_ONE);+ column.type === RelationTypes.ONE_TO_ONE);const version: number = isV1Heuristic? LinksVersion.V1diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.tsindex c51cfdfd6f..c13f58c7c0 100644--- a/packages/nocodb/src/services/columns.service.ts+++ b/packages/nocodb/src/services/columns.service.ts@@ -5073,14 +5073,21 @@ export class ColumnsService implements IColumnsService {};}- const revType = getRevType(- (param.column as Pick<LinkToAnotherColumnReqType, 'type'>)- .type as RelationTypes,- );-- const relationType = (+ // Normalize V1 types to V2 equivalents when using junction table+ // HM with junction table is effectively OM, BT with junction table is effectively MO+ let normalizedType = (param.column as Pick<LinkToAnotherColumnReqType, 'type'>).type as RelationTypes;+ if (isMMLike) {+ if (normalizedType === RelationTypes.HAS_MANY) {+ normalizedType = RelationTypes.ONE_TO_MANY;+ } else if (normalizedType === RelationTypes.BELONGS_TO) {+ normalizedType = RelationTypes.MANY_TO_ONE;+ }+ }++ const revType = getRevType(normalizedType);+ const relationType = normalizedType;// Use singular for ONE_TO_ONE and MANY_TO_ONE, plural for othersconst defaultTitle = [@@ -5096,8 +5103,14 @@ export class ColumnsService implements IColumnsService {param.column.title ?? defaultTitle,),- uidt: isLinks ? UITypes.Links : UITypes.LinkToAnotherRecord,- type: (param.column as Pick<LinkToAnotherColumnReqType, 'type'>).type,+ // OO always uses LinkToAnotherRecord (same as V1 createOOColumn)+ uidt:+ relationType === RelationTypes.ONE_TO_ONE+ ? UITypes.LinkToAnotherRecord+ : isLinks+ ? UITypes.Links+ : UITypes.LinkToAnotherRecord,+ type: relationType,fk_model_id: table.id,@@ -5141,14 +5154,13 @@ export class ColumnsService implements IColumnsService {],reverseDefaultTitle,),- // BT reverse column should always be LinkToAnotherRecord (not Links)- // to match V1 behavior where BT doesn't show count/rollup+ // OO always uses LinkToAnotherRecord (same as V1 createOOColumn)uidt:- revType === RelationTypes.BELONGS_TO+ revType === RelationTypes.ONE_TO_ONE? UITypes.LinkToAnotherRecord: isLinks- ? UITypes.Links- : UITypes.LinkToAnotherRecord,+ ? UITypes.Links+ : UITypes.LinkToAnotherRecord,type: revType,version: isMMLike ? 2 : 1,