在未调用验证之前航行 [英] sails beforeValidation not called

查看:42
本文介绍了在未调用验证之前航行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到创建和更新都调用了 beforeValidation,所以我想在保存到数据库之前使用这个回调来操作发布的数据,但似乎没有调用 beforeValidation,因为 _csrf 被保存在数据库并且名称没有变硬.

I saw that the beforeValidation is called for both create and update so I'm thinking of using this callback to manipulate the posted data before saving to the database but it seems like beforeValidation is not being called because _csrf is being save in the database and the name is not slugified.

示例:

var slugify = require('slug');
.....
beforeValidation: function(values, next){
 // don't save _csrf token in database
 if(values._csrf) delete values._csrf;
 // slugify the name before saving in the database
 values.name = slugify(values.name);
 next();
} 

谢谢

推荐答案

因为 waterline 生命周期回调 名称已更改:)

Because waterline lifecycle callback names have changed :)

beforeValidation 现在是 beforeValidateafterValidation 现在是 afterValidate.

beforeValidation is now beforeValidate, and afterValidation is now afterValidate.

这篇关于在未调用验证之前航行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆