[10.x] Fix runPaginationCountQuery not working properly for union queries #52314
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've created a pull request previously that has been closed due to missing tests and I've added them now.
I've recently stumbled across a bug where the total number of items displayed in Laravel Nova was incorrect after updating the index query to use unions. The total would always be equal to the page size even though there are more items in the pagination.
I started debugging the issue and found the following line
Illuminate\Database\Query\Builder::runPaginationCountQuery
:As we can see from the code above, it's cloning the query without
orders
,limit
andoffset
when there are unions in the query. However, if we have a look at thelimit
function from the same class:We can see that the property for unions is
unionLimit
and notlimit
.After searching through the issues, I found something that was closed previously because they did not provide a repository to test: #38639
Therefore, I made a repository to show the bug in action: https://github.com/chinleung/laravel-bug-52170