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

Query analyser gets confused when a join alias is equal to the relation name #554

Open
DCoderLT opened this issue Mar 22, 2024 · 0 comments

Comments

@DCoderLT
Copy link

Hi,

this code fragment triggers a “Could not analyse QueryBuilder with dynamic arguments” error.

$builder = $entityManager->createQueryBuilder();
$builder->from(MyEntity::class, 'rr');
$builder->addSelect('rr');
$builder->leftJoin('rr.user', 'user');
$builder->addSelect('user');
$builder->leftJoin('user.role', 'r');
$builder->addSelect('r');

// Error here: Could not analyse QueryBuilder with dynamic arguments.
$query = $builder->getQuery();

But as soon as I change the alias to be different from the relation name, the analyser stops raising the error:

$builder = $entityManager->createQueryBuilder();
$builder->from(MyEntity::class, 'rr');
$builder->addSelect('rr');
$builder->leftJoin('rr.user', 'u');
$builder->addSelect('u');
$builder->leftJoin('u.role', 'r');
$builder->addSelect('r');

// no error
$query = $builder->getQuery();

I have no problem changing the alias name, but I had no idea that this error could be triggered by that . I had to resort to putting $builder->getQuery(); after every line to see which line set it off :)

I’m using the latest versions of phpstan with 2.x versions of doctrine packages:

phpstan/extension-installer 1.3.1
phpstan/phpdoc-parser       1.27.0
phpstan/phpstan             1.10.64
phpstan/phpstan-doctrine    1.3.64
phpstan/phpstan-symfony     1.3.9
doctrine/dbal               2.13.9
doctrine/orm                2.11.3
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