Skip to content

Fix fetch join being disabled when an alias is selected twice - #12655

Open
dziulatex wants to merge 1 commit into
doctrine:2.20.xfrom
dziulatex:fix/gh12585-repeated-select-alias
Open

dziulatex wants to merge 1 commit into
doctrine:2.20.xfrom
dziulatex:fix/gh12585-repeated-select-alias

Conversation

@dziulatex

Copy link
Copy Markdown

Fixes #12585

Selecting the same identification variable twice, e.g. SELECT u, p, p FROM CmsUser u LEFT JOIN u.phonenumbers p, silently disabled the fetch join: the data was correct, but every collection stayed uninitialized and was lazy loaded with one query per parent row.

Parser::$identVariableExpressions kept one select expression per alias, so the second p replaced the first. fixIdentificationVariableOrder() only moves the expressions it knows about, so the first p was left at the head of the select clause, ahead of its parent u. The hydrator then met the child before the parent and dropped the association from the fetched hints for the whole result.

The parser now keeps every select expression of an alias and moves all of them. Nothing is added to or removed from the AST, so queries without a repeated alias produce the same SQL as before.

The test covers an entity result and a mixed result (entity plus scalar); both fail without the fix.

Targeting 2.20.x as the lowest maintained branch, the code is the same on 3.x. On 3.x the property is typed (private array), so merging up conflicts on the docblock line only.

AI-assisted: I used Claude Code to locate the cause and draft the fix and the test. I reviewed the change, ran the full test suite, phpcs and PHPStan locally, and can explain every line of it.

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

Successfully merging this pull request may close these issues.

1 participant