Skip to content

Commit

Permalink
fix(objection): table name 'xxx' specified more than once
Browse files Browse the repository at this point in the history
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 stalniy#17
  • Loading branch information
Christian Erhardt committed Apr 30, 2021
1 parent 310a784 commit 396cec0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/sql/src/lib/objection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ function joinRelation(relationName: string, query: QueryBuilder<Model>) {
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;
}
Expand Down

0 comments on commit 396cec0

Please sign in to comment.