I have an ENUM field with a type: DataTypes.ENUM(-1, 0, 1, 2) let’s call it myEnum.
When a record is updated : typeof record.myEnum is string if I update myEnum typeof record.myEnum is number if I update an other field
ENUM field custom conditional formatting is not working
I have a custom conditionnal formatting on myEnum with altered values. The values are not altered so the conditional formatting is not working.
ENUM display settings should be working with numbers
Context
Project name: MyCater
Team name: All
Environment name: all env => production/dev…
Agent (forest package) name & version: forest-express-sequelize@9.3.8
Database type: MySQL
Recent changes made on your end if any:
The problem seems to come from the update of the package from
forest-express-sequelize@8.4.7 to forest-express-sequelize@9.3.8
I’ve just checked on my side with forest-express-sequelize@9, I was not able to reproduce your issue.
My enum field is well sent as a number when I update it (and it should not be sent if other fields are updated but not this one!) and the alter value feature is working well.
So we need to dig a bit more to found out where is your issue.
Could you please:
Tell me how you defined your enum field in your DB
Tell me what edit widget did you choose
Show me the payload that is sent when you say it’s sent as a string
and it should not be sent if other fields are updated but not this one!
=> Yes I was checking in the beforeSave() hook of the model so I had every fields
Tell me how you defined your enum field in your DB
=> It’s a TINYINT(1) with a default value at 0
Tell me what edit widget did you choose
=> I chose dropdown with all values
Judging from your widget edit settings, it seems that the Alter Data feature is working at least there!
When I asked you the payload that is sent when you say it’s sent as a string, I was thinking about inside your browser inside the network tab of the inspector.
Could you please share this?
And what do you do actually in the beforeSave hook?
And what do you do actually in the beforeSave hook?
I check the active value, that’s how I found out the problem, but it’s after the log.
When I asked you the payload that is sent when you say it’s sent as a string, I was thinking about inside your browser inside the network tab of the inspector.
The request body inside the network tab is the same as in routes/products.js.
I’ve retried today, and strangely I was able to reproduce your problem.
It seems that we are not dealing well with this Enum of numbers.
Let me check why and if we can fix this.
In the meantime, I guess a workaround could be to define your field like this DataTypes.INTEGER. The alter values should work fine in the display widget settings, and you could use the dropdown you wanted in the edit widget (to limit what values could be entered).
@MarcoGarcia what’s strange here is that I tried on a project with typescript and it doesn’t even let me create this enum definition because it expects only strings on that function
Hello @MarcoGarcia, do you still have this bug in your project ?
I’ve tried to reproduced it with Sequelize and MySQL without success,
in both cases (Creation & Update) I received a correct number as value in beforeSave hook of Sequelize.