Fix multiple relationship display

This commit is contained in:
Adria Navarro 2023-10-02 15:00:51 +02:00
parent 15bec7aae8
commit 46c40f011e
1 changed files with 11 additions and 5 deletions

View File

@ -21,15 +21,21 @@
function getRelationships(tables) { function getRelationships(tables) {
const relatedColumns = {} const relatedColumns = {}
tables.forEach(({ name: tableName, schema }) => { tables.forEach(({ name: tableName, schema, _id: tableId }) => {
Object.values(schema).forEach(column => { Object.values(schema).forEach(column => {
if (column.type !== "link") return if (column.type !== "link") return
relatedColumns[column._id] ??= {} const columnId =
relatedColumns[column._id].through = column.through ||
relatedColumns[column._id].through || column.through (column.main
? `${tableId}_${column.fieldName}__${column.tableId}_${column.foreignKey}`
: `${column.tableId}_${column.foreignKey}__${tableId}_${column.fieldName}`)
relatedColumns[column._id][column.main ? "from" : "to"] = { relatedColumns[columnId] ??= {}
relatedColumns[columnId].through =
relatedColumns[columnId].through || column.through
relatedColumns[columnId][column.main ? "from" : "to"] = {
...column, ...column,
tableName, tableName,
} }