使用 SailsJS 中的 Waterline ORM,我的默认值是autoCreatedAt
and autoUpdatedAt
设置为 false,但我仍然需要仅使用不同的字段名称(DBA 请求)来实现该功能。有没有办法:
- 为自动生成的字段指定不同的列名称,或者
- 手动模拟属性定义中的相同行为,或者
- 我可以在模式中保留自定义字段吗
created_ts
and updated_ts
使用数据库模式本身中的触发器进行更新(但我仍然需要 Waterline 来读取它们)?
提前致谢。
我刚刚打开了两个拉取请求来实现此功能;
- One to 水线模式 https://github.com/balderdashy/waterline-schema/pull/23以便架构构建器考虑到这一点
- One to 吃水线 https://github.com/balderdashy/waterline/pull/946以便时间戳行为按预期工作。
您还可以关注这个问题 https://github.com/balderdashy/waterline/issues/754.
将其合并到您的模型中,而不是例如:
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
creationDate: {
columnName: 'created_ts',
type: 'datetime',
defaultsTo: function() {return new Date();}
},
updateDate: {
columnName: 'updated_ts',
type: 'datetime',
defaultsTo: function() {return new Date();}
}
},
beforeUpdate:function(values,next) {
values.updateDate = new Date();
next();
}
你可以这样做:
autoCreatedAt: 'created_ts',
autoUpdatedAt: 'updated_ts'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)