From da92c3bb0526470547ad5dab367b6a1e1fe63556 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 12 Dec 2024 14:01:56 +0100 Subject: [PATCH] Don't include unnecessary joins --- packages/backend-core/src/sql/sql.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/backend-core/src/sql/sql.ts b/packages/backend-core/src/sql/sql.ts index 4691cd71ba..0fe7e0ca57 100644 --- a/packages/backend-core/src/sql/sql.ts +++ b/packages/backend-core/src/sql/sql.ts @@ -1239,6 +1239,12 @@ class InternalBuilder { if (!toTable || !fromTable) { continue } + + // Don't include if not required + if (relationship.from && !fields.find(f => f === relationship.from)) { + continue + } + const relatedTable = tables[toTable] if (!relatedTable) { throw new Error(`related table "${toTable}" not found in datasource`)