sequelize / sequelize-auto

Automatically generate bare sequelize models from your database.
2.9k stars 527 forks source link

Fix timestamps & paranoid field comparison #576

Closed honzajerabek closed 2 years ago

honzajerabek commented 2 years ago

Hi there, currently the timestamp and paranoid fields are not working well when the model is using different casing than camel case.

With setting { "timestamps": true, "underscored": true }, the fields names are compared to createdat / updatedat etc, but their field names are created_at, updated_atetc. This causes that fields are not being correctly recognized as timestamps / paranoids and their fields are included in the model definition.

Current implementation

// field = 'created_at'
field.toLowerCase() === 'createdat'  // --->  'created_at' !== 'createdat'

The change compares the field name recased to camel case with the corresponding camel case name

// field = 'created_at'
recase('c', field) === 'createdAt'  // ---> 'createdAt' === 'createdAt'
steveschmitt commented 2 years ago

Good catch! Thanks!