sequelize-slugify
sequelize-slugify copied to clipboard
Not working with DataTypes.VIRTUAL
- 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.

What do you see instead?
Additional information
I resolved the issue by removing the following lines:
// if nothing change (new appears as changed)
if(!forceGenerateSlug && !changed) {
return instance;
}
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.
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
@jarrodconnolly any update about this?
@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
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.