diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 2cf4ef286..f4558371b 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -13,6 +13,7 @@ namespace Sonata\DoctrineORMAdminBundle\Filter; +use Doctrine\ORM\Query\Expr\Comparison; use Doctrine\ORM\Query\Expr\Orx; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface as BaseProxyQueryInterface; use Sonata\AdminBundle\Filter\Filter as BaseFilter; @@ -189,8 +190,8 @@ private function addOrParameter(BaseProxyQueryInterface $query, $parameter): voi $expressionParts = $expression->getParts(); - if (isset($expressionParts[0]) && \is_string($expressionParts[0]) && - 0 === strpos($expressionParts[0], ':sonata_admin_datagrid_filter_query_marker') + if (isset($expressionParts[0]) && $expressionParts[0] instanceof Comparison && + 0 === strpos($expressionParts[0]->getLeftExpr(), "'sonata_admin_datagrid_filter_query_marker_a'") ) { $expression->add($parameter); @@ -204,8 +205,7 @@ private function addOrParameter(BaseProxyQueryInterface $query, $parameter): voi if (null === $groupName) { // Add the ":sonata_admin_datagrid_filter_query_marker" parameter as marker for the `Orx` expression. - $orExpression->add($qb->expr()->isNull(':sonata_admin_datagrid_filter_query_marker')); - $qb->setParameter('sonata_admin_datagrid_filter_query_marker', 'sonata_admin.datagrid.filter_query.marker'); + $orExpression->add($qb->expr()->neq("'sonata_admin_datagrid_filter_query_marker_a'", "'sonata_admin_datagrid_filter_query_marker_b'")); } else { self::$groupedOrExpressions[$groupName] = $orExpression; } diff --git a/tests/Filter/FilterTest.php b/tests/Filter/FilterTest.php index 9b3938411..38a374dac 100644 --- a/tests/Filter/FilterTest.php +++ b/tests/Filter/FilterTest.php @@ -169,7 +169,7 @@ public function orExpressionProvider(): iterable yield 'Missing "or_group" option, fallback to DQL marker' => [ 'SELECT e FROM MyEntity e WHERE 1 = 2 AND (:parameter_1 = 4 OR 5 = 6)' - .' AND (:sonata_admin_datagrid_filter_query_marker IS NULL' + .' AND (\'sonata_admin_datagrid_filter_query_marker_a\' <> \'sonata_admin_datagrid_filter_query_marker_b\'' .' OR e.project LIKE :project_0 OR e.version LIKE :version_1) AND 7 = 8', [ [