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
Fix first and last when records are not loaded in a sorted relationship #37807
base: main
Are you sure you want to change the base?
Fix first and last when records are not loaded in a sorted relationship #37807
Conversation
b137583
to
9863eae
Compare
I agree with @p8 that #39525 would be a better approach to solve this, though it wouldn't be an "automatic" solution. One problem with this PR is that it doesn't address the order of A larger problem, though, is that it affects |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
@p8 / @jonathanhefner I've just added my failing test case (just a cherry-pick of my commit) to the #39525 PR and is still failing. We should consider mix both solutions in a single PR? Maybe we could wait until the other PR is merged and then adapt this PR to fix "my" problem on top of the previous (better) solution. WDYT? |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Waiting for merging of #39525 to rebase and rework this solution |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Still waiting for #39525 to rebase and rework this solution |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Still waiting for #39525 to rebase and rework this solution |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Still waiting for #39525 to rebase and rework this solution |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Still waiting for #39525 to rebase and rework this solution |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Still waiting for #39525 to rebase and rework this solution |
Summary
Fix
last
andfirst
methods on a sorted relationship with elements with the same order criteria.A test was added in 9863eae and is failing with current implementation, for all databases tests, i.e.:
The underlying problem is that
first
andlast
when the relationship is not loaded in the parent record uses an optimization based on the database to retrieve the items. The optimization applies correctly the order criteria and also aLIMIT
clause to minimize the retrieved data to only the amount of records requested (1 by default, but can be used for.last(4)
).The solution proposed is to add the default ordering criteria (based on
implicit_order_column
andprimary_key
) to disambiguate the sorting on the database.Related issues
This PR adds a second column for
implicit_order_column
=> #37626? Am I duplicating the solution and it's already solved? @pawurb?Probably solving this issue #36475?
No, after reproducing the case with the fix applies is still failing.