Query analyser gets confused when a join alias is equal to the relation name
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing the reported QueryBuilder sequence, especially the leftJoin where the alias equals the relation name, and call getQuery() to trigger analysis. Compare it with the version using the alias "u"; done means the equivalent alias should no longer produce the dynamic-arguments error.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- PHP
- Stars
- 678
- Forks
- 122
- Avg merge
- 5d 18h
- Merged PRs (30d)
- 3
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phpstan/phpstan-doctrine
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
phpstan/phpstan-doctrine#785 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
phpstan/phpstan-doctrine#792 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
phpstan/phpstan-doctrine#788 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
phpstan/phpstan-doctrine#763 ·
All issues in phpstan/phpstan-doctrine
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100