Repository navigation
v3: sourceKey feature for hasMany doesn't work if where clause specified in include (#7141) - #7147
Conversation
…dentifier or left.primaryKeyAttribute for attrLeft. Also includes integration test.
…om hasMany even with an include while respecting a specified sourceKey. Adds an integration test.
|
@LoneWolfPR, thanks for your PR! By analyzing the history of the files in this pull request, we identified @mbroadst, @janmeier and @mickhansen to be potential reviewers. |
Codecov Report
Continue to review full report at Codecov.
|
|
Any chance this can get merged in sometime soon (assuming it meets all merge requirements)? We have a project that needs this pretty badly with multiple developers needing it. |
| } | ||
|
|
||
| query += ';'; | ||
|
|
There was a problem hiding this comment.
Please remove the whitespace changes (it makes the changes easier to cherry-pick onto master)
| describe('sourceKey with where clause in include', function() { | ||
| beforeEach(function() { | ||
| var User = this.sequelize.define('User', | ||
| { username: Sequelize.STRING, email: Sequelize.STRING }, |
There was a problem hiding this comment.
Could you change it to something that uses field (email: { type: Sequelize.STRING, field: 'mail' } or similar - So we can make sure this works (and continues to work) even when the field is called something other in the DB than in the model
There was a problem hiding this comment.
Username attribute and indexes are not needed for this test
…then made to address the test breaking. All tests pass now.
|
@janmeier I've addressed all your requests. I believe it should be good to go now. Thanks for reviewing. Let me know if there are anymore issues. |
v3: sourceKey feature for hasMany doesn't work if where clause specified in include (#7141) (#7147) * Initial Commit * Stops test from removing test/integration/assets/es6project.js * Fixes impromper syntax when specifying the use of association.sourceIdentifier or left.primaryKeyAttribute for attrLeft. Also includes integration test. * Updates changelog. * Adds link to issue in changelog entry. * Added 'Future' header to changelog entry * Removed changelog update as requested. * Updates changelog. Fixes query-generator to properly build queries from hasMany even with an include while respecting a specified sourceKey. Adds an integration test. * Added back removed whitespace per request. * Updates test in include altered field name in source key. Fixes were then made to address the test breaking. All tests pass now. * Adds back removed whitespace.
|
Cherry-picked in 7d3172d |
|
Thanks for the adressing my feedback quickly @LoneWolfPR 🎉 |
|
@janmeier no problem. Glad I could help. What's the timeline for this going out to the npm? |
|
Thanks @LoneWolfPR. Just found this bug myself and was very happy to see it fixed already 😄 |
v3: sourceKey feature for hasMany doesn't work if where clause specified in include (sequelize#7141) (sequelize#7147) * Initial Commit * Stops test from removing test/integration/assets/es6project.js * Fixes impromper syntax when specifying the use of association.sourceIdentifier or left.primaryKeyAttribute for attrLeft. Also includes integration test. * Updates changelog. * Adds link to issue in changelog entry. * Added 'Future' header to changelog entry * Removed changelog update as requested. * Updates changelog. Fixes query-generator to properly build queries from hasMany even with an include while respecting a specified sourceKey. Adds an integration test. * Added back removed whitespace per request. * Updates test in include altered field name in source key. Fixes were then made to address the test breaking. All tests pass now. * Adds back removed whitespace.
|
I've been having an issue here where the field name is not the same as the model property name. So, if the 'field' is set and it's different the column name this isn't working unless you use the field instead of the column name, unlike any of the other properties. sequelize/lib/associations/has-many.js Lines 88 to 98 in 3168d54 Line 88 is using Once |
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)?Futurein the changelog?NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open.
Description of change
This fixes the issue mentioned in #7141. Previously
sourceKeywas only respected in a find from hasMany association if the include did not contain a where clause. This fixes that issue so that even with a where clause specified thesourceKeysupplied by the user will be respected.