Reputation: 5283
I have my model defined with all of the attributes in snake case. I've also set timestamps: true
and underscored: true
in the config, yet those options do not convert the createdAt
, updatedAt
and deletedAt
to snake case.
What is the correct way of converting the automatically generated timestamps to snake case?
Upvotes: 0
Views: 893
Reputation: 58523
This is for createdAt
, updatedAt
and deletedAt
:
If you are using Version5: (DOC)
underscored: true, // <--- You need only this
Override the name of the createdAt attribute if a string is provided, or disable it if false. Timestamps must be true. Underscored field will be set with underscored setting.
And if the Below version5 : (DOC)
Override the name of the createdAt column if a string is provided, or disable it if false. Timestamps must be true. Not affected by underscored setting.
You need to do some extra work like this :
var User = sequelize.define('User', {
createdAt: 'created_at',
updatedAt: 'updated_at'
}, {
timestamps: true,
underscored: true
});
// ------------------------ OR -----------------------
var User = sequelize.define('User', {
createdAt: {
field: 'created_at',
type: Sequelize.DATE
},
updatedAt: {
field: 'updated_at',
type: Sequelize.DATE
}
}, {
timestamps: true,
underscored: true
});
Upvotes: 1