我正在处理我的应用程序,一切正常,但在将系统重新安装到Windows 10后,我总是有一个电子邮件验证失败 . 我真的不认为这是因为Windows 10,但它只是改变了 .
为了测试我创造了新的闪亮模型:
module.exports = {
attributes: {
email: {
type: 'string',
required: true,
unique: true,
email: true
}
}
}
如果我用 sails console
启动应用程序并输入 TestModel.create({ email: 'alex@yahoo.com' }).exec(function(err, created) { console.log(err); console.log(created); })
我会得到这样的东西:
错误(E_VALIDATION):: 1属性在WLValidationError.WLError无效(C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ lib \ waterline \ error \ WLError.js: 26:15)新的WLValidationError(C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ lib \ waterline \ error \ WLValidationError.js:20:28)在C:\用户\我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ lib \ waterline \ query \ validate.js:46:43 at allValidationsChecked(C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ lib \ waterline \ core \ validations.js:210:5)在C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ node_modules \ async \ lib \ async.js:49:16 at done(C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ node_modules \ async \ lib \ async.js: 239:19)在C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ node_modules \ async \ lib \ async.js:40:16 at C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ lib \ waterline \ core \ validations.js:201 :14:C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ node_modules \ async \ lib \ async.js:49:16 at done(C:\ Users \ My name是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ node_modules \ async \ lib \ async.js:239:19)at C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ node_modules \ async \ lib \ async.js:40:16 at C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ lib \ waterline \ core \ validations.js:164:64在C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ node_modules \ async \ lib \ async.js:162:20 at C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ node_modules \ async \ lib \ async.js:230:13 at _arrayEach(C:\ Users \我的名字是Alex \ AppData \ R在_each(C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules)oaming \ npm \ node_modules \ sails \ node_modules \ waterline \ node_modules \ async \ lib \ async.js:81:9) \ waterline \ node_modules \ async \ lib \ async.js:72:13)发送给TestModel的无效属性:•email•“email”验证规则输入失败:'alex@yahoo.com'
如果我禁用电子邮件验证,一切都很好 .
{ email: 'alex@yahoo.com',
createdAt: '2015-08-08T21:09:25.118Z',
updatedAt: '2015-08-08T21:09:25.118Z',
id: 1 }
自己的电子邮件验证方法 - 不是很好的解决方案 .
我试过像数据库重新安装这样琐碎的蠢事,但它没有帮助 . 抱歉我的英文不好,希望我能在这里找到答案 .
2 回答
我现在有一个奇怪的解决方案 . 我将属性类型更改为
'email'
并删除了email: true
类型 .现在它有效 . 它对我来说没问题,但它没有记录,我仍然想知道为什么默认方式不起作用 .
根据waterline docs:
因此,当您设置的类型不是core types水线之一时,将使用它来验证其中一个验证rules supported by Anchor中的类型并将数据保存为字符串
因此,定义这样的模式将起作用: