sails beforeValidation not called

青春壹個敷衍的年華 提交于 2019-12-10 21:03:32

问题


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.

Example:

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

Thanks


回答1:


Because waterline lifecycle callback names have changed :)

beforeValidation is now beforeValidate, and afterValidation is now afterValidate.



来源:https://stackoverflow.com/questions/22480072/sails-beforevalidation-not-called

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