Is it possible to rename `createdAt` and `updatedAt` in sails.js / waterline

こ雲淡風輕ζ 提交于 2019-12-04 02:34:00
Tristan Foureur

I just opened two pull requests to implement this feature;

  • One to waterline-schema so that the schema builder takes this into account
  • One to waterline so that the timestamp behaviour works as expected.

You can also follow this issue.

With this merged, in your model, instead of having for example :

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

You can just do :

autoCreatedAt: 'created_ts',
autoUpdatedAt: 'updated_ts'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!