diff --git a/src/Filter/FilterLogic.php b/src/Filter/FilterLogic.php index c90fadb..f2dff99 100644 --- a/src/Filter/FilterLogic.php +++ b/src/Filter/FilterLogic.php @@ -89,7 +89,7 @@ public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $q // Problem: too hard to add the joins from the extensions and correctly initialize the QueryNameGenerator // Workaround may fail if extensions did any joins and filters also, or if both use the QueryNameGenerator - $filters = $this->getFilters($resourceClass, $operationName, true); + $filters = $this->getFilters($resourceClass, $operationName, true); foreach ($filters as $filter) { $filter->apply($newQb, $newQng, $resourceClass, $operationName, $context); } @@ -154,7 +154,7 @@ public function apply(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $q throw new \RuntimeException("Could not replace criteria from filters"); } - /** + /** * @return array of Doctrine\ORM\Query\Expr\* and/or string (DQL), * each of which must be self-contained in the sense that the intended * logic is not compromised if it is combined with the others and other @@ -183,6 +183,9 @@ public function generateExpressions(QueryBuilder $queryBuilder, QueryNameGenerat */ protected function doGenerate($queryBuilder, $queryNameGenerator, $resourceClass, $operationName, $context) { + if (empty($context['filters'])) { + return []; + } $oldWhere = $queryBuilder->getDQLPart('where'); // replace by marker expression @@ -347,7 +350,7 @@ protected function replaceInnerJoinsByLeftJoins(QueryBuilder $queryBuilder) { $joinExp->getConditionType(), $joinExp->getCondition(), $joinExp->getIndexBy() - ); + ); } else { $result[$rootAlias][$i] = $joinExp; } diff --git a/tests/Filter/FilterLogicWithAnnotationTest.php b/tests/Filter/FilterLogicWithAnnotationTest.php index 6e2c07e..d8ae8d1 100644 --- a/tests/Filter/FilterLogicWithAnnotationTest.php +++ b/tests/Filter/FilterLogicWithAnnotationTest.php @@ -73,6 +73,23 @@ public function testNoLogic() 'DQL'); } + public function testOrNoFilter() + { + $reqData = null; + parse_str('or', $reqData); + // var_dump($reqData); + $context = ['filters' => $reqData]; + foreach ($this->filters as $filter) { + $filter->apply($this->testEntityQb, $this->queryNameGen, TestEntity::class, 'get', $context); + } + + $this->assertEquals( + str_replace(' +', '', "SELECT o FROM Metaclass\FilterBundle\Entity\TestEntity o"), + $this->testEntityQb->getDQL(), + 'DQL'); + } + public function testDdFilterAnd() { $reqData = null;