Skip to content
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(postgres, sqlite): map conflictFields to column names in Model.upsert #14199

Closed
wants to merge 19 commits into from

Conversation

wbourne0
Copy link
Member

@wbourne0 wbourne0 commented Mar 5, 2022

Pull Request Checklist

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

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

Description Of Change

fixes an issue where the attributes provided in conflictFields wouldn't be mapped to column names.

Closes #14150

fixes an issue where the attributes provided in conflictFields wouldn't be mapped to column names.
@wbourne0 wbourne0 self-assigned this Mar 5, 2022
@WikiRik WikiRik requested a review from ephys March 14, 2022 17:12
ephys
ephys previously requested changes Apr 8, 2022
Copy link
Member

@ephys ephys left a comment

Choose a reason for hiding this comment

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

Only change request :)

src/model.js Outdated
Comment on lines 2616 to 2620
options.conflictFields = options.conflictFields
&& options.conflictFields.map(
attr => (this.rawAttributes[attr] && this.rawAttributes[attr].field) || attr,
);

Copy link
Member

Choose a reason for hiding this comment

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

just a small code style change

Suggested change
options.conflictFields = options.conflictFields
&& options.conflictFields.map(
attr => (this.rawAttributes[attr] && this.rawAttributes[attr].field) || attr,
);
options.conflictFields = options.conflictFields?.map(
attr => (this.rawAttributes[attr]?.field) || attr,
);

This piece of code is used a lot in sequelize. We could add a Model.getColumnName(attributeName: string): string util which does this

Copy link
Member

Choose a reason for hiding this comment

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

Do we want to add Model.getColumnName(attributeName: string): string in this PR already?

@wbourne0 wbourne0 dismissed ephys’s stale review April 8, 2022 22:45

made the requested change

@WikiRik WikiRik requested a review from ephys July 11, 2022 14:05
@wbourne0 wbourne0 changed the title fix(upsert): map conflictFields to column names fix(postgres, sqlite): map upsert conflictFields to column names Sep 27, 2022
@wbourne0 wbourne0 changed the title fix(postgres, sqlite): map upsert conflictFields to column names fix(postgres, sqlite): map conflictFields to column names in Model.upsert Sep 27, 2022
@@ -2544,6 +2544,10 @@ Specify a different name for either index to resolve this issue.`);
const updateValues = Utils.mapValueFieldNames(updatedDataValues, options.fields, this);
const now = Utils.now(this.sequelize.dialect);

options.conflictFields = options.conflictFields?.map(
attr => (this.rawAttributes[attr]?.field) || attr,
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a breaking change, should we rename conflictFields to conflictAttributes in this PR? (see comment in #13419)

@ephys ephys requested review from a team and removed request for a team March 24, 2023 11:03
@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2023

This pull request has been marked as maybe-abandoned and has not seen any activity for 14 days. It will be closed if no further activity occurs within the next 30 days. If you would still like to work on this, please comment to let us know and the label will be removed.

@github-actions github-actions bot added the stale label Apr 8, 2023
@github-actions github-actions bot closed this May 8, 2023
@muraliprajapati
Copy link

Can we re-open this PR and merge? This fix can land in v7.

@WikiRik
Copy link
Member

WikiRik commented Mar 22, 2024

@muraliprajapati Some further updates might need to be done in order to merge this since it's been a year since the last update. We've done quite some work internally since then. Feel free to open a new PR that adds this feature and new tests to the current codebase

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

Successfully merging this pull request may close these issues.

SQL field name used instead of property name in conflictFields
5 participants