Sails.js 将标准传递给SailsJS中的验证和生命周期回调 更新

Sails.js 将标准传递给SailsJS中的验证和生命周期回调 更新,sails.js,waterline,Sails.js,Waterline,正如评论部分所指出的,这类似于S.O.上发布的另一个问题。答案指向水线核心内的一个(或特征?) 我会让这个问题打开,因为这个问题和上面提到的问题都是不同的,但都依赖于相同的底层功能来工作 一旦水线供应,将提供完整的解决方案 操作 是否有方法在验证和更新回调之前通过条件 这方面的用例场景是,我想从条件中获取primaryKey值,并基于该值查询数据库 具体示例:我有两个表、作者和文章(一个作者有许多文章)。现在,我希望每个作者文章的标题属性是唯一的 因此: 现在,当更新第一篇文章的标题时,检查它

正如评论部分所指出的,这类似于S.O.上发布的另一个问题。答案指向水线核心内的一个(或特征?)

我会让这个问题打开,因为这个问题和上面提到的问题都是不同的,但都依赖于相同的底层功能来工作

一旦水线供应,将提供完整的解决方案


操作 是否有方法在验证和更新回调之前通过条件

这方面的用例场景是,我想从条件中获取primaryKey值,并基于该值查询数据库

具体示例:我有两个表、作者和文章(一个作者有许多文章)。现在,我希望每个作者文章的标题属性是唯一的

因此:

现在,当更新第一篇文章的标题时,检查它是否已经存在

Article.update(1, {title: "title2"});
现在,我在文章模型中为title属性提供了一个自定义验证器,如下所示:

... // irrelevant
attributes: {
    ... // irrelevant
    title: {
        type: "string",
        required: true,
        uniqueTitle: function(cb) {
            console.log(this) // {title: "newTitleValue"}
            // so this is quite usless :(
            cb();
        }
    }
},
beforeUpdate: [
    function _checkTitle(values, cb) {
        console.log(values) // same as above {title: "newTitleValue"}
        console.log(this) // the model, with no criteria or primaryKey property set, which becomes useless :(
        cb();
    }
]
...

关于如何访问这些挂钩中的更新标准,您有什么想法吗(

我想我能帮上忙you@AlexisN-是的,这基本上就是他们解决问题的方法。但是水线的问题,也就是说,基本上就是这个问题。
... // irrelevant
attributes: {
    ... // irrelevant
    title: {
        type: "string",
        required: true,
        uniqueTitle: function(cb) {
            console.log(this) // {title: "newTitleValue"}
            // so this is quite usless :(
            cb();
        }
    }
},
beforeUpdate: [
    function _checkTitle(values, cb) {
        console.log(values) // same as above {title: "newTitleValue"}
        console.log(this) // the model, with no criteria or primaryKey property set, which becomes useless :(
        cb();
    }
]
...