From 396cec0df43256efd50e0d1fd4c526f1b2b9ed40 Mon Sep 17 00:00:00 2001 From: Christian Erhardt Date: Fri, 30 Apr 2021 13:24:45 +0000 Subject: [PATCH] fix(objection): table name 'xxx' specified more than once When a relation was already joined with `withGraphJoined`, ucast was adding the relation a second time. Now a check for the relation is performed. fixes #17 --- packages/sql/src/lib/objection.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/sql/src/lib/objection.ts b/packages/sql/src/lib/objection.ts index 0273dfb..e519fa8 100644 --- a/packages/sql/src/lib/objection.ts +++ b/packages/sql/src/lib/objection.ts @@ -13,6 +13,14 @@ function joinRelation(relationName: string, query: QueryBuilder) { return false; } + // Check if relation has already been joined e.g. with 'withGraphJoined' + if (query.hasWithGraph()) { + const graphExpression = query.graphExpressionObject(); + if (graphExpression.$childNames.indexOf(relationName) !== -1) { + return true; + } + } + query.joinRelated(relationName); return true; }