简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM