Skip to content

BUGFIX: prevent creating new alias for columns after filters changed#12228

Open
danfraticiu wants to merge 1 commit intodoctrine:3.6.xfrom
danfraticiu:GH-12225-one-to-many-index-by-alias-desync
Open

BUGFIX: prevent creating new alias for columns after filters changed#12228
danfraticiu wants to merge 1 commit intodoctrine:3.6.xfrom
danfraticiu:GH-12225-one-to-many-index-by-alias-desync

Conversation

@danfraticiu
Copy link

As described in issue 12225

When there is a oneToMany relation where the children use single table inheritance, if the relation is re-fetched after a filter changed, SingleTablePersister::getSelectColumnsSQL will generate new aliases for the child entity fields. Then ResultSetMapping::addIndexBy picks the first alias that matches the indexBy field, which doesn't exist in the updated list. This causes ObjectHydrator:502 to throw an ErrorException: Warning: Undefined array key

This PR prevent creating new aliases.

The change is inspired by the code in BasicEntityPersister::getSelectColumnSQL which reuses the aliases that already exist.

@danfraticiu danfraticiu force-pushed the GH-12225-one-to-many-index-by-alias-desync branch from a47e551 to 6d435a6 Compare November 10, 2025 13:38
@derrabus derrabus changed the base branch from 3.5.x to 3.6.x December 30, 2025 17:36
@tomme87
Copy link

tomme87 commented Jan 16, 2026

Is it possible to get this fix into 2.20.x too?
I added these changes to 2.20.9 and it seams to have solved the issue for me.

Also; this is kind of a critical bug too us, since we are unable to upgrade doctrine before this is fixed. Hope this get fixed as soon as possible 🙏

If anyone have a temporary workaround it would be very much appreciated.

@tomme87
Copy link

tomme87 commented Feb 2, 2026

A better solution to this issue might be to change AbstractEntityInheritancePersister::getSelectColumnSQL to check if the column alias already exist, similar to how it's done in BasicEntityPersister::getSelectColumnSQL

$columnAlias = null;
if ($this->currentPersisterContext->rsm->hasColumnAliasByField($alias, $field)) {
  $columnAlias = $this->currentPersisterContext->rsm->getColumnAliasByField($alias, $field);
}

if ($columnAlias === null) {
  $columnAlias = $this->getSQLColumnAlias($fieldMapping->columnName);
}

Added a PR with this solution: #12373

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.

2 participants