Hello!
My model attribute is defined like this:
firstName: {
type: Sequelize.STRING(60)
},
Sequelize instance is configured with: underscored: true and underscoredAll: true.
However, when I run the app it throws an error: column "firstName" does not exist.
I'm using pre-existing database without the sync feature. All table and column names are in the snake case, e.g. users.first_name. Is is possible to have my database in snake_case, but properties in my application in camelCase without manually specifying the tableName and field options?
Also I would like createdAt and updatedAt properties to be automatically added to my model, but by defined like created_at and updated_at in the database. Is it also possible? I can't find a way to do this without re-defining each field for all the models manually using field option.
Thank you!
The underscored option only handles the columns generated by sequelize - resulting in created_at, user_id etc. - You need to use the field option to achieve what you want.
If you want it to apply to all your tables you could do so in a beforeDefine hook
sequelize.beforeDefine(function (attributes, options) {
// Loops through attributes and sets field
});
Most helpful comment
The
underscoredoption only handles the columns generated by sequelize - resulting increated_at,user_idetc. - You need to use thefieldoption to achieve what you want.If you want it to apply to all your tables you could do so in a beforeDefine hook