gpt4 book ai didi

node.js - 更改 CreatedAt/UpdateAt 属性的字段名称

转载 作者:IT老高 更新时间:2023-10-28 23:03:52 26 4
gpt4 key购买 nike

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

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

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

最佳答案

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

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();
}

Waterline options doc .

关于node.js - 更改 CreatedAt/UpdateAt 属性的字段名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24560942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com