Skip to content

fix(doctrine): extract alias from sql function in orderby parts#8240

Merged
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/querychecker-orderby-sql-function-alias-8083
Jun 4, 2026
Merged

fix(doctrine): extract alias from sql function in orderby parts#8240
soyuka merged 1 commit into
api-platform:4.3from
soyuka:fix/querychecker-orderby-sql-function-alias-8083

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented Jun 4, 2026

Summary

QueryChecker::hasOrderByOnFetchJoinedToManyAssociation() derives an alias by splitting each orderBy part on .. When the orderBy is a SQL function call such as find_in_set(t.type, 'INTERVIEW'), the split yields ['find_in_set(t', "type, 'INTERVIEW')"] — the first segment is then passed to QueryBuilderHelper::traverseJoins(), which throws:

LogicException: The alias "find_in_set(t" does not exist in the QueryBuilder.

Fix: strip the leading SQL function prefix (everything up to and including () before treating the segment as an alias. Applies the patch the reporter validated locally.

Fixes #8083

Test plan

  • New unit test testHasOrderByOnFetchJoinedToManyAssociationWithSqlFunctionInOrderBy reproduces the crash without the fix and passes with it.
  • All existing QueryCheckerTest cases remain green (15/15).
  • PHPStan + php-cs-fixer dry-run clean on changed files.

QueryChecker::hasOrderByOnFetchJoinedToManyAssociation exploded each
orderBy part on "." to derive an alias. For SQL function calls such as
"find_in_set(t.type, 'INTERVIEW')", the first segment was "find_in_set(t",
which QueryBuilderHelper::traverseJoins then rejected with
LogicException: The alias "find_in_set(t" does not exist.

Strip any leading SQL function prefix before treating the segment as an
alias.

Fixes api-platform#8083
@soyuka soyuka merged commit cfe1bc3 into api-platform:4.3 Jun 4, 2026
105 of 108 checks passed
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