Skip to content

Commit

Permalink
FilterProcessor: Don't utilize subquery filters if relations are join…
Browse files Browse the repository at this point in the history
…ed anyway
  • Loading branch information
nilmerg committed Mar 6, 2020
1 parent 99e8756 commit 3be6fd1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Compat/FilterProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ protected function requireAndResolveFilterColumns(Filter $filter, Query $query)
foreach ($filterCombinations as $column => $filters) {
// The relation path must be the same for all entries
$relationPath = $filters[0]->metaData['relationPath'];

// In case the parent query also selects the relation we may not require a subquery.
// Otherwise we form a cartesian product and get unwanted results back.
$selectedByParent = isset($query->getWith()[$relationPath]);

// Though, only single equal comparisons or those chained with an OR may be evaluated on the base
if ($selectedByParent && $sign !== '!=' && (count($filters) === 1 || $filter instanceof FilterOr)) {
continue;
}

$relation = $query->getResolver()->resolveRelation($relationPath);
$subQuery = $query->createSubQuery($relation->getTarget(), $relationPath);
$subQuery->columns([new Expression('1')]);
Expand Down

0 comments on commit 3be6fd1

Please sign in to comment.