Skip to content

fix(model): create instance with many-to-many association with extra column (#10034) #10050

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

Merged
merged 2 commits into from
Oct 23, 2018

Conversation

tsasaki609
Copy link
Contributor

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

fix #10034
I tried to include extra attributes in the condition processing the scope.

if (attr === include.association.foreignKey || attr === include.association.otherKey) {
continue;
}
values[attr] = instance[include.association.through.model.name][attr];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if instance[include.association.through.model.name][attr] is defined only then we should set values[attr]

lib/model.js Outdated
if (include.association.through.model.rawAttributes[attr]._autoGenerated) {
continue;
}
if (attr === include.association.foreignKey || attr === include.association.otherKey) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both if statements can be folded into single check?

@codecov
Copy link

codecov bot commented Oct 21, 2018

Codecov Report

Merging #10050 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10050      +/-   ##
==========================================
+ Coverage    96.3%    96.3%   +<.01%     
==========================================
  Files          63       63              
  Lines        9410     9415       +5     
==========================================
+ Hits         9062     9067       +5     
  Misses        348      348
Impacted Files Coverage Δ
lib/model.js 96.68% <100%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a0545bf...74acd72. Read the comment docs.

@tsasaki609
Copy link
Contributor Author

Thanks for the review. I fixed it.

Copy link
Contributor

@sushantdhiman sushantdhiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, a few more changes and this should be good to go

expect(foo.bars[0].foobar).to.not.equal(null);
expect(foo.bars[0].foobar.baz).to.equal('baz...');
}, () => {
expect.fail();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect.fail is not required promise rejection will bubble up

}).then(() => {
return Foo.findOne({ include: Bar });
}).then(foo => {
expect(foo.name).to.equal('foo...');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please repeat these checks for data returned just after create as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

@sushantdhiman sushantdhiman merged commit 5dc314b into sequelize:master Oct 23, 2018
@sushantdhiman
Copy link
Contributor

Thanks @tsasaki609 👍

@papb
Copy link
Member

papb commented Oct 24, 2018

Thank you very much @tsasaki609, excellent work! 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create instance with many-to-many association with extra column
3 participants