-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[8.x] Cursor pagination fixes #37915
Conversation
f939f96
to
3a51209
Compare
@paras-malhotra would appreciate a review if you're willing. |
@driesvints Thank you for your hard work, really appreciate it. Hydration seems to be working properly for the pivot now! Sadly, I am still having weird behaviour when browsing the "next" page. On my playground repo, if you're browsing the next page on the Using an alias seems to fix the issue on the playground, however, I tried in my own app and I get the same error even with the alias... I've got no idea what's going on, the code of the playground is based from my app and should be similar... I will keep you updated once I figured out... but for now im banging my head against the wall |
I'll need to check in on that on Thursday. I also see it failing but also can't figure it out atm. |
Ok so after spending some time debugging, the alias is now working properly on my real app as well. I was sorting on a non-unique column, my records all had the same timestamps and the next page returned no results, failing to build the previous cursor because Stupid mistake, just like I did on the playground app: it should be sorting on The app is still acting weird when not using an alias though. Eg: $friends = $this->user()
->friends()
->latest('friends.id')
->cursorPaginate(); I am not sure if there is an easy way to fix this. Maybe creating an alias automatically when a dot is used would do the trick. Just need to make sure it does not collide. I will investigate further this week. |
@driesvints I went through the code. I think this PR looks good to go. Definitely seems to have been an oversight on my part to not hydrate the pivot relations and not fetch the original columns for the where clause. I guess #37762 changed the where clauses entirely but this logic would still need to be applied to that PR. |
06a4b80
to
6cbb48a
Compare
6a84797
to
fdec468
Compare
@kamui545 think I got a fix in for the issue you were experiencing. The app you shared is now fully working with this PR. Can you try to verify that? @paras-malhotra we pushed one more commit to fix the above. It basically will retrieve attributes on a pivot relationship when the table matches with the first part of the dot notation of a parameter name. I'll try some more use case with other relationship queries tomorrow. But this will essentially allow to filter on non-unique column names as long as the table is prefixed. |
@driesvints Thank you again! It seems to fix ordering on ambiguous columns. However, I noticed another issue: #37999 |
This PR fixes
twothree things:Before the second fix, the query builder would generate the following invalid query:
Now it will generate:
The reason for this is that sql engines need an actual column to sort and can't rely on an aliased column of a result set. By de-aliasing the given columns we circumvent this issue.
I don't think this contains anything breaking but I'm unsure about the usage to detect the column aliasing:
I saw this was used in the base query grammar class as well with the
wrap
method so I think this will be fine.This PR will conflict with #37762
Fixes #37400