Skip to content

Fix field name mapping issue for bulk create queries with ON DUPLICATE UPDATE - #9162

Merged
sushantdhiman merged 4 commits into
sequelize:masterfrom
andriis:fix/bulk-create
Mar 13, 2018
Merged

sushantdhiman merged 4 commits into
sequelize:masterfrom
andriis:fix/bulk-create

Conversation

@andriis

@andriis andriis commented Mar 9, 2018 •

Copy link
Copy Markdown
Contributor

Close #9016

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

@codecov

codecov Bot commented Mar 9, 2018 •

Copy link
Copy Markdown

Codecov Report

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

@sushantdhiman
sushantdhiman requested a review from a team March 10, 2018 08:34
@private
*/
bulkInsertQuery(tableName, attrValueHashes, options, rawAttributes) {
bulkInsertQuery(tableName, fieldValueHashes, options, fieldMappedAttributes) {

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.

Might seems like API change but internally this was already the case, attrValueHashes are actually values mapped by their field names. Same is true for rawAttributes. So I have renamed these arguments

});

expectsql(sql.bulkInsertQuery(User.tableName, [{ user_name: 'testuser', pass_word: '12345' }], { updateOnDuplicate: ['username', 'password', 'updatedAt'] }, User.rawAttributes),
expectsql(sql.bulkInsertQuery(User.tableName, [{ user_name: 'testuser', pass_word: '12345' }], { updateOnDuplicate: ['user_name', 'pass_word', 'updated_at'] }, User.fieldRawAttributesMap),

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.

a breaking change?

What this test assumes seems incorrect to me, if records are mapped by field name so should updateOnDuplicate values. bulkInsertQuery should just use whatever data given to it to generate query as its a low level API, converting attributes to fields etc stuff should be handled at model level api.

I think it should be ok to merge this change, records are expected to be mapped by field name so should updateOnDuplicate

@sushantdhiman
sushantdhiman merged commit 83dfc5a into sequelize:master Mar 13, 2018
@sushantdhiman

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 4.36.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

BulkCreate: updateOnDuplicate option is not mapping fields correctly

5 participants