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

Not working with DataTypes.VIRTUAL #53

Open
lucassimines opened this issue Jul 9, 2021 · 6 comments
Open

Not working with DataTypes.VIRTUAL #53

lucassimines opened this issue Jul 9, 2021 · 6 comments

Comments

@lucassimines
Copy link

  • Node.js: v14.16.1
  • OS: Darwin Lucass-MacBook-Pro.local 20.5.0 Darwin Kernel Version 20.5.0: Sat May 8 05:10:31 PDT 2021; root:xnu-7195.121.3~9/RELEASE_ARM64_T8101 arm64
  • Sequelize: 6.6.4
  • Database: PostgresSQL 13

What steps will reproduce the bug?

Page.init(
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: UUIDV4,
        allowNull: false,
        primaryKey: true
      },
      title: {
        type: DataTypes.JSONB,
        allowNull: false
      },
      _title: {
        type: DataTypes.VIRTUAL,
        get() {
          const title: any = this.get('title');
          return title[langs[0]];
        }
      },
    },
    {
      sequelize,
      tableName: 'pages',
      modelName: 'Page'
    }
  );

  SequelizeSlugify.slugifyModel(Page, { source: ['_title'] });

How often does it reproduce? Is there a required condition?

What is the expected behavior?

The slug column is not getting _title Virtual column as the documentation says.

Screen Shot 2021-07-09 at 14 49 01

What do you see instead?

Additional information

@lucassimines
Copy link
Author

I resolved the issue by removing the following lines:

// if nothing change (new appears as changed)
      if(!forceGenerateSlug && !changed) {
        return instance;
      }

@jarrodconnolly
Copy link
Owner

Thank you, that is helpful. I am not sure removing that is the best course of action as it will likely have other side effects.

I will have to look into why DataTypes.VIRTUAL is not generating the slug.

@jarrodconnolly
Copy link
Owner

It appears that fields of type DataTypes.VIRTUAL are not detected as changed, which makes sense as there is no way to know the previous version since it is not a stored field.

The documentation referenced appears to have been added without unit tests to back it up :(

I will continue to investigate, but in the meantime, it may be safer to manually call regenerateSlug() as in the unit test that I added.
https://github.com/jarrodconnolly/sequelize-slugify/blob/main/jest-tests/slug-generation.test.js#L70

@lucassimines
Copy link
Author

@jarrodconnolly any update about this?

@agjs
Copy link

agjs commented Feb 3, 2023

@jarrodconnolly Hey :-). Any updates on this, and a side question, is the library still being maintained? Some of these issues have been here for a while, and I wonder if you maybe need a hand with this? I'm happy to help if you are willing to pair on it.

Cheers

@jarrodconnolly
Copy link
Owner

Hello, thank you for your comments.

This library is still maintained, I try to investigate and solve any issues as they come up. This issue was left open because at the time could only find a workaround as described and added a unit test to show the issue.

I am always open to pull requests or suggestions on how to solve issues.

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

No branches or pull requests

3 participants