Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Conversation

thijsvdanker
Copy link
Contributor

@thijsvdanker thijsvdanker commented Mar 27, 2024

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

@thijsvdanker thijsvdanker changed the title Binding order is incorrect when using cursor paginate with multiple unions with a where [11.x] Binding order is incorrect when using cursor paginate with multiple unions with a where Mar 27, 2024
@thijsvdanker thijsvdanker changed the title [11.x] Binding order is incorrect when using cursor paginate with multiple unions with a where Binding order is incorrect when using cursor paginate with multiple unions with a where Mar 27, 2024
This is necessary to allow cursor pagination to add a where binding to
the right union query.
@thijsvdanker
Copy link
Contributor Author

I've implemented the first solution in this PR.

@driesvints driesvints changed the title Binding order is incorrect when using cursor paginate with multiple unions with a where [11.x] Binding order is incorrect when using cursor paginate with multiple unions with a where Mar 28, 2024
@driesvints
Copy link
Member

@thijsvdanker if this is a bug fix it should ideally go to 10.x

@driesvints
Copy link
Member

Please send this to 10.x

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.

None yet

2 participants