Browse Source

fix: hide relation column with associative table(mm)

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/1668/head
Pranav C 3 years ago
parent
commit
1c4d470782
  1. 26
      packages/nocodb/src/lib/noco-models/Column.ts
  2. 26
      packages/nocodb/src/lib/noco/meta/api/metaDiffApis.ts
  3. 4
      scripts/sdk/swagger.json

26
packages/nocodb/src/lib/noco-models/Column.ts

@ -878,4 +878,30 @@ export default class Column<T = any> implements ColumnType {
exclude_id && { id: { neq: exclude_id } }
));
}
static async markAsSystemField(
colId: string,
system = true,
ncMeta = Noco.ncMeta
) {
// get existing cache
const key = `${CacheScope.COLUMN}:${colId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
// update data
o.system = system;
// set cache
await NocoCache.set(key, o);
}
// update system field in meta db
await ncMeta.metaUpdate(
null,
null,
MetaTable.COLUMNS,
{
system
},
colId
);
}
}

26
packages/nocodb/src/lib/noco/meta/api/metaDiffApis.ts

@ -17,6 +17,7 @@ import UITypes from '../../../sqlUi/UITypes';
import mapDefaultPrimaryValue from '../helpers/mapDefaultPrimaryValue';
import { Tele } from 'nc-help';
import getColumnUiType from '../helpers/getColumnUiType';
export enum MetaDiffType {
TABLE_NEW = 'TABLE_NEW',
TABLE_REMOVE = 'TABLE_REMOVE',
@ -730,6 +731,7 @@ async function isMMRelationAvailable(
if (col.uidt === UITypes.LinkToAnotherRecord) {
const colOpt = await col.getColOptions<LinkToAnotherRecordColumn>();
if (
colOpt &&
colOpt.type === RelationTypes.MANY_TO_MANY &&
colOpt.fk_mm_model_id === assocModel.id &&
colOpt.fk_child_column_id === colChildOpt.fk_parent_column_id &&
@ -761,7 +763,7 @@ export async function extractAndGenerateManyToManyRelations(
}
}
// todo: impl proper way to identify m2m relation
// todo: impl better method to identify m2m relation
if (belongsToCols?.length === 2 && normalColumns.length < 5) {
const modelA = await belongsToCols[0].colOptions.getRelatedTable();
const modelB = await belongsToCols[1].colOptions.getRelatedTable();
@ -819,6 +821,28 @@ export async function extractAndGenerateManyToManyRelations(
}
await Model.markAsMmTable(assocModel.id, true);
// mark has many relation associated with mm as system field in both table
for (const btCol of [belongsToCols[0], belongsToCols[1]]) {
const colOpt = await btCol.colOptions;
const model = await colOpt.getRelatedTable();
for (const col of await model.getColumns()) {
if (col.uidt !== UITypes.LinkToAnotherRecord) continue;
const colOpt1 = await col.getColOptions<LinkToAnotherRecordColumn>();
if (!colOpt1 || colOpt1.type !== RelationTypes.HAS_MANY) continue;
if (
colOpt1.fk_child_column_id !== colOpt.fk_child_column_id &&
colOpt1.fk_parent_column_id !== colOpt.fk_parent_column_id
)
continue;
await Column.markAsSystemField(col.id);
break;
}
}
} else {
if (assocModel.mm) await Model.markAsMmTable(assocModel.id, false);
}

4
scripts/sdk/swagger.json

@ -1865,13 +1865,13 @@
]
}
},
"/api/v1/db/meta/filters/{filterParentId}/children": {
"/api/v1/db/meta/filters/{filterGroupId}/children": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "filterParentId",
"name": "filterGroupId",
"in": "path",
"required": true
}

Loading…
Cancel
Save