-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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: Separate queries are not subQueries #12144
fix: Separate queries are not subQueries #12144
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion will fail if you remove the !include.separate
check
@@ -405,6 +405,26 @@ describe(Support.getTestDialectTeaser('Model'), () => { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to this test, please add an integration test here
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 test
ornpm run test-DIALECT
pass 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