Skip to content

[10.x] Binding order is incorrect when using cursor paginate with multiple unions with a where #50810

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Conversation

thijsvdanker
Copy link
Contributor

When using cursorPaginate on a query that has multiple unions, the binding order is incorrect.

This happens because:

https://github.com/laravel/framework/blob/11.x/src/Illuminate/Database/Concerns/BuildsQueries.php#L436
adds the bindings for the cursor where to the end of the bindings and not in the position that they should be.

The result is a query that binds the wrong values to the wrong parameters in the query.

Possible solutions I can now think of are:

  1. make the bindings for union a nested array until the bindings are resolved to make the query and add the cursor bindings to the right index
  2. re-order the union bindings after adding the cursor bindings

This PR implements the first solution.

This PR is similar to #50795 but made against 10.x

This is necessary to allow cursor pagination to add a where binding to
the right union query.
@taylorotwell
Copy link
Member

I would rather not change the structure of the union bindings - I fear it could be a breaking change.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants