π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix: use isMMOrMMLike for V2 om/mo handling in getLinkInfo and getParentChildContext
Pranavfc1cb94bc80c
diff --git a/packages/nocodb-sdk/src/lib/unifiedMeta/getLinkInfo.ts b/packages/nocodb-sdk/src/lib/unifiedMeta/getLinkInfo.tsindex f9b7915206..b24e2934e3 100644--- a/packages/nocodb-sdk/src/lib/unifiedMeta/getLinkInfo.ts+++ b/packages/nocodb-sdk/src/lib/unifiedMeta/getLinkInfo.ts@@ -3,6 +3,7 @@ import type { NcContext, UnifiedMetaType } from '~/lib';import { getColOptions } from '~/lib/unifiedMeta/getColOptions';import { getColumns } from '~/lib/unifiedMeta/getColumns';import { getLTARRelatedTable } from './getLTARRelatedTable';+import { isMMOrMMLike } from '~/lib/UITypes';/*case 1:@@ -74,7 +75,13 @@ export const getLinkInfo = async (column: linkColumn,});- switch (relationColOptions.type) {+ // Ensure colOptions is present for isMMOrMMLike check+ // (getColOptions may load via method without setting it on the column)+ const relationType = isMMOrMMLike({ ...linkColumn, colOptions: relationColOptions })+ ? RelationTypes.MANY_TO_MANY+ : relationColOptions.type;++ switch (relationType) {case RelationTypes.ONE_TO_ONE:case RelationTypes.BELONGS_TO:case RelationTypes.HAS_MANY: {@@ -117,7 +124,7 @@ export const getLinkInfo = async (: relationColOptions.type,} as UnifiedMetaType.ILinkInfo;}- case RelationTypes.MANY_TO_MANY: {+ case RelationTypes.MANY_TO_MANY:{const joinIds = [relationColOptions.fk_child_column_id,relationColOptions.fk_parent_column_id,diff --git a/packages/nocodb/src/models/LinkToAnotherRecordColumn.ts b/packages/nocodb/src/models/LinkToAnotherRecordColumn.tsindex 604db79087..13a7aa8b2d 100644--- a/packages/nocodb/src/models/LinkToAnotherRecordColumn.ts+++ b/packages/nocodb/src/models/LinkToAnotherRecordColumn.ts@@ -1,4 +1,4 @@-import { RelationTypes } from 'nocodb-sdk';+import { isMMOrMMLike, RelationTypes } from 'nocodb-sdk';import type { BoolType } from 'nocodb-sdk';import type Filter from '~/models/Filter';import type { NcContext } from '~/interface/config';@@ -308,36 +308,28 @@ export default class LinkToAnotherRecordColumn {let childContext = context;let parentContext = context;- // if hm then child belongs to the related table- // if oo(hm) then child belongs to the related table- // in these scenario overwrite context if fk_related_base_id is present- if (- this.fk_related_base_id &&- (this.type === RelationTypes.HAS_MANY ||- (this.type === RelationTypes.ONE_TO_ONE &&- !(- column ||- (await Column.get(context, { colId: this.fk_column_id }, ncMeta))- )?.meta?.bt))- ) {- childContext = refContext;- }-- // if mm link parent present in related table- // if bt then parent belongs to the related table- // if oo(bt) then parent belongs to the related table- // in these scenario overwrite context if fk_related_base_id is present- if (- this.fk_related_base_id &&- (this.type === RelationTypes.MANY_TO_MANY ||- this.type === RelationTypes.BELONGS_TO ||- (this.type === RelationTypes.ONE_TO_ONE &&- (- column ||- (await Column.get(context, { colId: this.fk_column_id }, ncMeta))- )?.meta?.bt))- ) {- parentContext = refContext;+ if (this.fk_related_base_id) {+ const col =+ column ||+ (await Column.get(context, { colId: this.fk_column_id }, ncMeta));++ // V2 om/mo/mm all use junction tables β parent always in related table+ if (isMMOrMMLike(col)) {+ parentContext = refContext;+ } else if (this.type === RelationTypes.HAS_MANY) {+ // hm: child (FK column) belongs to the related table+ childContext = refContext;+ } else if (this.type === RelationTypes.BELONGS_TO) {+ // bt: parent (PK column) belongs to the related table+ parentContext = refContext;+ } else if (this.type === RelationTypes.ONE_TO_ONE) {+ // oo: depends on which side holds the FK+ if (col?.meta?.bt) {+ parentContext = refContext;+ } else {+ childContext = refContext;+ }+ }}// propagate cache map