Repository navigation
fix(query-builder): wrap inner joins under left joins correctly - #11137
Conversation
| @@ -295,6 +295,51 @@ describe("query builder > joins", () => { | |||
| }), | |||
| )) | |||
|
|
|||
| it("should load results from a left join with a child inner join both of which have zero results", () => | |||
There was a problem hiding this comment.
Both these tests will fail on the current TypeORM version
gioboa
left a comment
There was a problem hiding this comment.
Can I ask you to solve the conflicts please?
PR Code Suggestions ✨Latest suggestions up to 9c15b7a
Previous suggestionsSuggestions up to commit f0bb366
Suggestions up to commit 77978eb
✅ Suggestions up to commit 089a6fb
|
||||||||||||||||||||||||||||||||||||
commit: |
|
@gioboa Done! Test are running and seemingly as expected 👍 As I mentioned in the bottom of the description, we've been running this fix in our production environment for the past year without issue. In fact, it ran as expected and we couldn't even update to the latest TypeORM without this fix. So assuming this is merged we finally can 👌 Btw, I think the suggestion from Qodo is not necessary as the query builder doesn't allow for out of order joins, correct? |
Code Review by Qodo (Alpha)
1. Multiple Root Joins Incorrectly Nested
|
Code Review by Qodo
1. Alias map prototype keys
|
# Conflicts: # src/query-builder/SelectQueryBuilder.ts
|
Persistent review updated to latest commit 608f127 |
…alls, update and add tests
|
Persistent review updated to latest commit 5d40f5a |
|
Persistent review updated to latest commit c7495bd |
…join # Conflicts: # src/query-builder/SelectQueryBuilder.ts # test/functional/relations/eager-relations/basic-eager-relations/basic-eager-relations.test.ts
|
Persistent review updated to latest commit 2c6bb5d |
|
|
Persistent review updated to latest commit 27f6c8e |
857b9d4 to
27f6c8e
Compare
|
I can't test |
@Cprakhar it's the typical issue when checking arrays - the order is important (the two posts are swapped). There are 2 more failing assertions at |
|
Thanks for the fix @harm-less! This will make it in the next patch release (1.0.1). |
|
@alumni That's great to hear, thank you! |



Description of change
Fixes #3080. After 6 years of knowing this issue exists, it's finally no more!
This StackOverflow still explain the case fairly well. Simply put, if the nested
INNER JOINreturns 0 rows, the entire query will by definition return 0 results even if theFROMtable or theLEFT JOINhad results. So theONcondition of the parentLEFT JOINwraps theINNER JOINin order to prevent this from happening.We are running this on a Postgres DB.
This is what the PR will do to queries. I took an advanced example from our application.
Before (current TypeORM version):
After (this PR):
I'll be runnning this code on our production environment soon. So I should have a better overview of this change in the coming days/weeks in case more info is needed.
Pull-Request Checklist