Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while filtering #449

Closed
fsteinbauer opened this issue Oct 16, 2017 · 5 comments
Closed

Error while filtering #449

fsteinbauer opened this issue Oct 16, 2017 · 5 comments

Comments

@fsteinbauer
Copy link

Type error: Argument 1 passed to Knp\Component\Pager\Event\Subscriber\Filtration\Doctrine\ORM\Query\WhereWalker::expressionContainsFilter() must be an instance of Doctrine\ORM\Query\AST\ConditionalExpression, instance of Doctrine\ORM\Query\AST\ConditionalTerm given, called in /vendor/knplabs/knp-components/src/Knp/Component/Pager/Event/Subscriber/Filtration/Doctrine/ORM/Query/WhereWalker.php on line 192

This error occurs, when the query is built with the query builder. If no filter is specified it works like a charm.

An example of the filter params:
?filterField=e.name&filterValue=example

Querybuilder

(It works when the between is commented out. After I comment this line in, the error above occurs. The Between statement is not the problem, it also occurs with a simple eq)

$qb = $this->createQueryBuilder('e');
$qb->orderBy('e.adressZip', 'ASC');
$qb->leftJoin('e.vertreter', 'u')
                ->leftJoin('u.vertretungen', 'v')
                ->andWhere($qb->expr()->orX(
                    $qb->expr()->eq('e.vertreter', ':userid'),
                    $qb->expr()->isNull('e.vertreter'),
                    $qb->expr()->andX(
                        $qb->expr()->eq('v.proxy', ':userid')
           //                    ,    $qb->expr()->between(':currentDate', 'v.start', 'v.end')
                    )
                ))
                ->setParameter('currentDate', new \DateTime(), \Doctrine\DBAL\Types\Type::DATETIME)
                ->setParameter('userid', $user->getId());

return $qb->getQuery();
@nicolasmure
Copy link
Contributor

Hello,

If you do not plan to have multiple expressions in your andX function (as the above example where the second expression is commented), I think you should replace the andX by its first expression directly :

->andWhere($qb->expr()->orX(
    $qb->expr()->eq('e.vertreter', ':userid'),
    $qb->expr()->isNull('e.vertreter'),
    $qb->expr()->eq('v.proxy', ':userid')
))

@polc polc added the Help user label Oct 18, 2017
@fsteinbauer
Copy link
Author

Hey @nicolasmure !

This is not the issue, both issues in the andX are needed. Just if the second one is uncommented, symfony crashes with the above stated exception.

@fsteinbauer
Copy link
Author

push

@nicolasmure
Copy link
Contributor

Hello,

Do you mind to make a repository having this bug so we can investigate on this ?

Thank you ;)

@garak
Copy link
Collaborator

garak commented Jul 23, 2019

Please follow related issue in knp-components

@garak garak closed this as completed Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants