fix: Separate queries are not subQueries#12144
fix: Separate queries are not subQueries#12144sushantdhiman merged 6 commits intosequelize:masterfrom
Conversation
|
Bleh keep failing on unrelated (and inconsistent) other tests... closing/re-opening again to retrigger build |
|
One more try... |
Codecov Report
@@ Coverage Diff @@
## master #12144 +/- ##
===========================================
+ Coverage 74.85% 95.87% +21.01%
===========================================
Files 86 92 +6
Lines 8373 9019 +646
===========================================
+ Hits 6268 8647 +2379
+ Misses 2105 372 -1733
Continue to review full report at Codecov.
|
| }); | ||
|
|
||
| expect(options.subQuery).to.equal(false); | ||
| expect(options.include[0].subQuery).to.equal(false); |
There was a problem hiding this comment.
This assertion will fail if you remove the !include.separate check
| expect(options.include[0].subQueryFilter).to.equal(false); | ||
| }); | ||
|
|
||
| it('should not tag a separate hasMany association with subQuery true', function() { |
There was a problem hiding this comment.
In addition to this test, please add an integration test here
There was a problem hiding this comment.
Added integration test
| const user = await task.createUser({ id: 2 }); | ||
| await user.createCompany({ id: 3 }); | ||
|
|
||
| const results = await Task.findAll({ |
There was a problem hiding this comment.
Based on (currently) failing SSCCE query: https://github.com/papb/sequelize-sscce/pull/71/files#diff-560223653e227eef1d7c120cb8cb74a7R91
|
Updated SSCCE to use this custom fork sequelize/sequelize-sscce#71 Helps visualize the change in SQL, shows it is now valid |
|
Thanks for this fix. If you want to have this ported to v5, Please open a PR targeting that branch |
Port of master PR: sequelize#12144 Only significant change is integration test was altered to use promise.then() rather than async/await
I had to rebase + squash commits because branches are so different, but hopefully this is enough |
Pull Request check-list
Please make sure to review and check all of these items:
npm run testornpm run test-DIALECTpass with this change (including linting)?Description of change
Resolves #12141
As stated in issue, I believe "separate" queries are being negatively impacted if their "parent" is required, even if that parent is not part of the current query.
The generated SQL expects the parent to be generating a literal subquery (wrapped in parentheses) but due to the nature of "separate" queries, that isn't actually happening.
This change fixes things locally for me.
I don't believe this portion of code is currently covered by unit-tests, and I'm not entirely sure where to start on a higher level integration test...Added unit test