【问题标题】:how to use createdAt and updatedAt in sails js如何在sails js中使用createdAt和updatedAt
【发布时间】:2019-09-09 07:05:29
【问题描述】:

createdAt 和 UpdatedAt 需要不同的时间

我在 Sails 模型中使用 autoCreatedAt 和 autoUpdatedAt.. 当我创建数据时,它会在两个字段(created_at 和 updated_at)中存储创建时间。 当我更新数据时,它会在两个字段中存储更新时间。 创建时我需要两个字段的静态时间(应该是创建时间)。当我更新它不应该影响创建时间。

created_at      : {type:'ref',columnType:'datetime',autoCreatedAt:true},
updated_at      : {type:'ref',columnType:'datetime',autoCreatedAt:true},

当创建两个字段时,都会存储创建时间。 更新时,两个字段都会存储更新时间。

【问题讨论】:

  • 再次检查您的代码...不应该是“autoUpdatedAt”吗?不会解释你得到的行为......

标签: sails.js


【解决方案1】:

根据@Salketer 的评论,您的代码应该是:

created_at      : {type:'ref',columnType:'datetime',autoCreatedAt:true},
updated_at      : {type:'ref',columnType:'datetime',autoUpdatedAt:true},

更多信息Sails Documentation

【讨论】:

    猜你喜欢
    • 2015-10-11
    • 2019-07-19
    • 1970-01-01
    • 2022-12-02
    • 2021-07-16
    • 1970-01-01
    • 2018-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多