Jampala Uday
Jampala Uday

Reputation: 21

Sequalize TimeStamps

I was facing a problem with TimeStamps, In my model I've specified like { timestamps: true, createdAt: 'createdOn', updatedAt: 'updatedOn', tableName: 'Employee' }); But in database both createdOn and updatedOn were storing date values, I want updatedOn as null because it was creating newly. Am I missing anything,Thanks in Advance.

Upvotes: 0

Views: 313

Answers (1)

Chase
Chase

Reputation: 3105

Unless you disable it, updatedAt and createdAt are provided by Sequelize without having to manually add them. - http://docs.sequelizejs.com/en/v3/docs/models-definition/#configuration

Creating a new row is considered an update and so yes, updatedAt and CreatedAt will both have the same timestamp on first write. If you really want to track whether or not something is new you might look into using a "status" column with an ENUM (for multiple status values) or a BOOLEAN to represent either new or not - http://docs.sequelizejs.com/en/v3/docs/models-definition/#data-types

Upvotes: 1

Related Questions