Sails.js 如何在Sails框架中仅为更新操作运行beforeValidate?

Sails.js 如何在Sails框架中仅为更新操作运行beforeValidate?,sails.js,Sails.js,我想知道在Sails框架中触发beforeValidate时的当前操作,请查看我的代码: module.exports = { attributes: { ... log: 'string' }, beforeValidate: function(values, cb) { // I want to know the action is create new record or update current record

我想知道在Sails框架中触发beforeValidate时的当前操作,请查看我的代码:

module.exports = {
    attributes: {
        ...
        log: 'string'
    },
    beforeValidate: function(values, cb) {

        // I want to know the action is create new record or update current record
        // If action is update, how to get primary key of record will be updated

        /*
        if (isCreateNewRecord) {
            values.log = 'New created...'; // for example
        } else {
            values.log = 'Update record ID: ' + recordID;
        }
        */

        cb();
    }
}

非常感谢你的帮助

嗯,你不应该那样做。。。这就是为什么我们在创建之前有
在更新之前有

beforeCreate:函数(值,cb){
values.log='newcreated…';
返回cb();
},
更新前:函数(valuesToUpdate,cb){
valuesToUpdate.log='更新记录ID:'+valuesToUpdate.ID;
返回cb();
}

签出。

我检查了文档,也在使用beforeUpdate时,我们可以获取recordID(记录的主键将被更新)吗?哎呀,我忘记了这个问题,我编辑了我的答案,并根据需要添加了记录id beforeUpdate valuesToUpdate.id==未定义,但更新后可以获取valuesToUpdate.id。我仍然希望在其他问题之前获得更新的主键,我也认为它不应该这样做。谢谢。
valuesToUpdate.id
此时应该存在。您是否重写了主键?sails blueprint,因此要将我的post更新为url/model/:id,然后将我的日志值更新为update.id,它将显示未定义