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

Using a variable to define multiple fields cause them to become weird #15503

Open
4 tasks
LCostaN opened this issue Dec 26, 2022 · 1 comment
Open
4 tasks

Using a variable to define multiple fields cause them to become weird #15503

LCostaN opened this issue Dec 26, 2022 · 1 comment

Comments

@LCostaN
Copy link

LCostaN commented Dec 26, 2022

Issue Creation Checklist

  • [X ] I understand that my issue will be automatically closed if I don't fill in the requested information
  • I have read the contribution guidelines

Bug Description

It seems when using variable as a way to reduce code lines it causes problem for sequelize.

Reproducible Example

Here is the link to the SSCCE for this issue:

export default class MyModel extends Model {
  static init(sequelize) {
    const repeatedDefinition = {
      type: Sequelize.INTEGER,
        defaultValue: 0,
        validate: {
          min: {
            args: [0],
            msg: 'Value should be between 0 and 7',
          },
          max: {
            args: [7],
            msg: 'Value should be between 0 and 7',
          },
        },
    };
    super.init({
      field1: repeatedDefinition,
      field2: repeatedDefinition,
      field3: repeatedDefinition,
      field4: repeatedDefinition,
      field5: repeatedDefinition,
      field6: repeatedDefinition,
      field7: repeatedDefinition,
    }, {
      sequelize,
      freezeTableName: true,
      tableName: 'myModels',
    });
    return this;
}

What do you expect to happen?

Quicken table field definition by using a variable and allow less lines of code.

What is actually happening?

It seems it confuses the fields in someway. I realized that when sending two fields with different values, it set one of the values to all other fields. Like

mymodel.update({field1: 4, field2: 2})

Expected this to update only field 1 and 2, but
field1 = 4 // Correct
field2 = 2 // Correct
field(3 to 7) = either 2 or 4 // Sometimes one, sometimes the other

Environment

To find the version numbers for the three systems below use the following commands:

  • sequelize@6.27.0
  • v18.12.0
  • Javascript
  • MySQL 8.0.31
  • mysql2 "^2.3.3"

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I will need guidance.
  • No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • [X ] No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.

Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.

@LCostaN LCostaN added pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet type: bug labels Dec 26, 2022
@ephys ephys added v6 and removed pending-approval Bug reports that have not been verified yet, or feature requests that have not been accepted yet labels Dec 27, 2022
@ephys
Copy link
Member

ephys commented Dec 27, 2022

I can confirm this bug exists in v6, but was fixed in @sequelize/core@^7.0.0-alpha.20. I don't know if it's possible to fix in Sequelize 6 unfortunately. The design flaw that caused this issue required introducing a breaking change

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

No branches or pull requests

2 participants