From 7ef09b6fece8b5866b76e7459ae728d0d7d24318 Mon Sep 17 00:00:00 2001 From: Gerard Burns Date: Tue, 5 Dec 2023 15:01:35 +0000 Subject: [PATCH] Fix Deleting and Remaking Relationships to the User Table (#12453) * Fix Deleting and Remaking Relationships to the User Table * change tables store related tables fetching * lint --- .../DataTable/modals/CreateEditColumn.svelte | 11 ----------- packages/builder/src/stores/backend/tables.js | 14 +++++++++++--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 4eb1f962f0..a99081de13 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -307,12 +307,6 @@ dispatch("updatecolumns") gridDispatch("close-edit-column") - if (saveColumn.type === LINK_TYPE) { - // Fetching the new tables - tables.fetch() - // Fetching the new relationships - datasources.fetch() - } if (originalName) { notifications.success("Column updated successfully") } else { @@ -339,11 +333,6 @@ confirmDeleteDialog.hide() dispatch("updatecolumns") gridDispatch("close-edit-column") - - if (editableColumn.type === LINK_TYPE) { - // Updating the relationships - datasources.fetch() - } } } catch (error) { notifications.error(`Error deleting column: ${error.message}`) diff --git a/packages/builder/src/stores/backend/tables.js b/packages/builder/src/stores/backend/tables.js index 457a58fdbb..51b8416eda 100644 --- a/packages/builder/src/stores/backend/tables.js +++ b/packages/builder/src/stores/backend/tables.js @@ -81,13 +81,21 @@ export function createTablesStore() { replaceTable(savedTable._id, savedTable) select(savedTable._id) // make sure tables up to date (related) - let tableIdsToFetch = [] + let newTableIds = [] for (let column of Object.values(updatedTable?.schema || {})) { if (column.type === FIELDS.LINK.type) { - tableIdsToFetch.push(column.tableId) + newTableIds.push(column.tableId) } } - tableIdsToFetch = [...new Set(tableIdsToFetch)] + + let oldTableIds = [] + for (let column of Object.values(oldTable?.schema || {})) { + if (column.type === FIELDS.LINK.type) { + oldTableIds.push(column.tableId) + } + } + + const tableIdsToFetch = [...new Set([...newTableIds, ...oldTableIds])] // too many tables to fetch, just get all if (tableIdsToFetch.length > 3) { await fetch()