diff --git a/packages/nc-gui/components/erd/utils.ts b/packages/nc-gui/components/erd/utils.ts index 9eddefaffa..9214cb5667 100644 --- a/packages/nc-gui/components/erd/utils.ts +++ b/packages/nc-gui/components/erd/utils.ts @@ -97,18 +97,46 @@ export function useErdElements(tables: MaybeRef, props: MaybeRef { - if (!modelId) return '' + function edgeLabel({ type, source, target, modelId, childColId, parentColId }: Relation) { + const typeLabel = type === 'mm' ? 'many to many' : 'has many' + + const parentCol = metasWithIdAsKey.value[source].columns?.find((col) => { + const colOptions = col.colOptions as LinkToAnotherRecordType + if (!colOptions) return false + + return ( + colOptions.fk_child_column_id === childColId && + colOptions.fk_parent_column_id === parentColId && + colOptions.fk_mm_model_id === modelId + ) + }) + + const childCol = metasWithIdAsKey.value[target].columns?.find((col) => { + const colOptions = col.colOptions as LinkToAnotherRecordType + if (!colOptions) return false + + return colOptions.fk_parent_column_id === (type === 'mm' ? childColId : parentColId) + }) + + if (!parentCol || !childCol) return - const mmModel = metasWithIdAsKey.value[modelId] + if (type === 'mm') { + if (config.showJunctionTableNames) { + if (!modelId) return undefined - if (!mmModel) return '' + const mmModel = metasWithIdAsKey.value[modelId] - if (mmModel.title !== mmModel.table_name) { - return `${mmModel.title} (${mmModel.table_name})` + if (!mmModel) return undefined + + if (mmModel.title !== mmModel.table_name) { + return `${mmModel.title} (${mmModel.table_name})` + } + + return mmModel.title + } } - return mmModel.title + return `${parentCol.title} ${typeLabel} ${childCol.title}` } function createNodes() { @@ -139,7 +167,6 @@ export function useErdElements(tables: MaybeRef, props: MaybeRef((acc, { source, target, childColId, parentColId, type, modelId }) => { let sourceColumnId, targetColumnId - let edgeLabel = '' if (type === 'hm') { sourceColumnId = childColId @@ -149,13 +176,19 @@ export function useErdElements(tables: MaybeRef, props: MaybeRef, props: MaybeRef, props: MaybeRef { if (isNode(el)) { + console.log(el.data.columnLength) + dagreGraph.setNode(el.id, { width: skeleton ? nodeWidth * 2.5 : nodeWidth, height: nodeHeight + (skeleton ? 250 : nodeHeight * el.data.columnLength),