Skip to content

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

Merged
sushantdhiman merged 2 commits into
sequelize:masterfrom
tsasaki609:add-extra-column
Oct 23, 2018
Merged

fix(model): create instance with many-to-many association with extra column (#10034)#10050
sushantdhiman merged 2 commits into
sequelize:masterfrom
tsasaki609:add-extra-column

Conversation

@tsasaki609

Copy link
Copy Markdown
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.

Comment thread lib/model.js
if (attr === include.association.foreignKey || attr === include.association.otherKey) {
continue;
}
values[attr] = instance[include.association.through.model.name][attr];

Copy link
Copy Markdown
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]

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

Copy link
Copy Markdown
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

codecov Bot commented Oct 21, 2018

Copy link
Copy Markdown

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
Copy Markdown
Contributor Author

Thanks for the review. I fixed it.

@sushantdhiman sushantdhiman left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Thanks @tsasaki609 👍

@papb

papb commented Oct 24, 2018

Copy link
Copy Markdown
Member

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