更改 CreatedAt/UpdateAt 属性的字段名称 [英] Change field name for CreatedAt / UpdateAt Attributes

查看:39
本文介绍了更改 CreatedAt/UpdateAt 属性的字段名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 SailsJS 中为现有的 MSSQL 表建模.不出所料,现有数据库中的表有一个 createdAt 和 updatedAt 列,类似于 SailsJS 框架生成的列.

I am attempting to model an existing MSSQL table in SailsJS. Unsurprisingly the tables in the existing database have a createdAt and updatedAt column similar to what is generated by the SailsJS framework.

有没有办法将 SailsJS 框架生成的属性的值赋给我定义的属性?例如:

attributes: {
    ...
    creationDate:{
        columnName:'cre_dt',
        type:'datetime',
        defaultsTo: this.createdAt
    }
    ...
}

推荐答案

否,但您可以完全关闭自动生成的属性并使用您自己的:

No, but you can turn off the auto-generated property entirely and use your own:

autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
    creationDate: {
        columnName: 'cre_dt',
        type: 'datetime',
        defaultsTo: function() {return new Date();}
    },
    updateDate: {
        columnName: 'upd_dt',
        type: 'datetime',
        defaultsTo: function() {return new Date();}
    }
},
//Resonsible for actually updating the 'updateDate' property.
beforeValidate:function(values,next) {
    values.updateDate= new Date();
    next();
}

请参阅水线选项文档.

这篇关于更改 CreatedAt/UpdateAt 属性的字段名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆