-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fix: include joined entity primary keys in pagination subquery #11669
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: include joined entity primary keys in pagination subquery #11669
Conversation
commit: |
595ec51 to
02e2d70
Compare
gioboa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mag123c
May I ask you to solve the conflicts please?
ff9cbb0 to
196609e
Compare
PR Code Suggestions ✨Latest suggestions up to 9064fa0
Previous suggestionsSuggestions up to commit 5429b85
Suggestions up to commit dae49c7
Suggestions up to commit f94b754
Suggestions up to commit 9ddcf86
Suggestions up to commit 17cab60
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@gioboa rebased onto master to resolve conflicts. |
gioboa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mag123c
gioboa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mag123c for your help
pkuczynski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Small suggestion to simplify the code...
| const hasValidKeys = | ||
| keys.length > 0 && | ||
| rawResults.length > 0 && | ||
| keys.some( | ||
| (key) => | ||
| rawResults[0].hasOwnProperty(key) && | ||
| rawResults[0][key] !== undefined, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const hasValidKeys = | |
| keys.length > 0 && | |
| rawResults.length > 0 && | |
| keys.some( | |
| (key) => | |
| rawResults[0].hasOwnProperty(key) && | |
| rawResults[0][key] !== undefined, | |
| ) | |
| const hasValidKeys = keys.some(key => key in (rawResults[0] ?? {})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasValidKeys is also a bit misleading/unclear. Should we maybe call it primaryKeysSelected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
primaryKeysSelected much clear than hasValidKeys
Description of change
This change fixes an issue where leftJoin combined with skip/take pagination was not properly loading related entities due to missing primary keys in the pagination subquery.
The SelectQueryBuilder uses a two-query approach for pagination with joins to avoid N+1 problems. The first query selects primary keys with pagination, and the second query loads full data for those keys. The bug was in the first query not including joined entity primary keys, causing entity identification issues.
Pull-Request Checklist
masterbranchskipandtakedon't work for join tables if primary key is not selected #11662