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

Semantical Error on conditionally added joins to the QueryBuilder #624

Open
yguedidi opened this issue Nov 8, 2024 · 0 comments
Open

Semantical Error on conditionally added joins to the QueryBuilder #624

yguedidi opened this issue Nov 8, 2024 · 0 comments

Comments

@yguedidi
Copy link

yguedidi commented Nov 8, 2024

I got this error

QueryBuilder: [Semantical Error] line X, col X near 't.other IN(':
Error: 't' is not defined.

With the following code:

        if (empty($things) && empty($others)) {
            return [];
        }

        $qb = $this->createQueryBuilder('s');

        $condition = $qb->expr()->orX();

        if (!empty($things)) {
            $condition->add('s.thing IN(:things)');
            $qb->setParameter('things', $things);
        }

        if (!empty($others)) {
            $condition->add('t.other IN(:others)');
            $qb
                ->addSelect('t')
                ->join('s.thing', 't')
                ->setParameter('others', $others)
            ;
        }

        $qb->andWhere($condition);

        return $qb->getQuery()->getResult();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant