Skip to content

fix(laravel): alias the joins of nested OrderFilter properties - #8903

Merged
soyuka merged 2 commits into
api-platform:5.0from
BenMacha:fix-laravel-order-filter-join-alias-5-0
Dec 1, 2026
Merged

soyuka merged 2 commits into
api-platform:5.0from
BenMacha:fix-laravel-order-filter-join-alias-5-0

Conversation

@BenMacha

Copy link
Copy Markdown
Contributor
Q A
Branch? 5.0
Tickets -
License MIT
Doc PR -

Ordering on two nested properties of the same relation fails with a SQL error, because OrderFilter joins the related table once per property, without an alias:

#[QueryParameter(key: 'authorOrder[:property]', filter: OrderFilter::class, properties: ['author.name', 'author.id'])]
class Book extends Model {}

GET /api/books?authorOrder[author.name]=asc&authorOrder[author.id]=desc

  • before: 500, ambiguous column name: authors.id (... left join "authors" on ... left join "authors" on ...; MySQL says Not unique table/alias)
  • after: 200, books sorted by author name, then author id

Each join now gets an alias built from the relation path (authors_author). The join is only added when it is not already there, and the ORDER BY uses that alias. Ordering on a self-referencing relation (e.g. parent.name) hits the same problem and is fixed the same way. I added the parameter to the workbench Book model; the test is testOrderFilterOnSeveralPropertiesOfTheSameRelation in src/Laravel/Tests/EloquentTest.php.

Ordering on two properties of the same relation (or on a self-referencing relation) joined the
same table twice without an alias and failed with an ambiguous column SQL error. Joins are now
aliased by relation path and added only once.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-30T08:57:39.371678Z
We couldn’t complete this review. Comment @codex review to try again.
edfca6a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@BenMacha
BenMacha force-pushed the fix-laravel-order-filter-join-alias-5-0 branch from edfca6a to 99315fd Compare November 30, 2026 12:35
@soyuka
soyuka merged commit 48a3208 into api-platform:5.0 Dec 1, 2026
4 of 115 checks passed
@soyuka

soyuka commented Dec 1, 2026

Copy link
Copy Markdown
Member

thanks @BenMacha!

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