Skip to content

[13.x] Fix cursorPaginate() columns on union queries with multiple orders - #62272

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:cursor-paginate-union-multiple-orders
Nov 2, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:cursor-paginate-union-multiple-orders

Conversation

@xurshudyan

Copy link
Copy Markdown
Contributor

Cursor paginating a union where one query aliases a column breaks on the second page if you order by more than one column:

DB::table('videos')->select('id', 'start_time as created_at')
    ->union(DB::table('news')->select('id', 'created_at'))
    ->orderBy('id')
    ->orderBy('created_at', 'desc')
    ->cursorPaginate(15);

#50882 resolved the column per union query, but only for the first order. The rest still use the main query's alias, so the news query gets where "start_time" < ? and fails because that column doesn't exist there.

@xurshudyan xurshudyan changed the title [13.x] Fix cursorPaginate() columns on union queries with multiple orders. [13.x] Fix cursorPaginate() columns on union queries with multiple orders Oct 31, 2026
@taylorotwell
taylorotwell merged commit d10fc6c into laravel:13.x Nov 2, 2026
64 checks passed
binaryfire added a commit to hypervel/components-backup that referenced this pull request Nov 3, 2026
Laravel fixed cursor pagination columns on union queries with several
orders. Hypervel's paginateUsingCursor() already resolves each union
member's columns by output position, so only the test is ported.

Ports the test from laravel/framework#62272 on 13.x at b20bf7f442.

Tests: testPaginationWithMultipleAliasesAndMultipleOrders passes on
SQLite, MySQL, MariaDB and PostgreSQL.
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