帆'水线电子邮件验证始终失败

时间:2015-08-08 21:08:45

标签: sails.js waterline

我正在处理我的应用程序,一切正常,但在将系统重新安装到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:\ Users \我的名字是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       在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 \我的名字是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       在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       在C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ node_modules \ async \ lib \ async.js:230:13       在_arrayEach(C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ node_modules \ async \ lib \ async.js:81:9)       在_each(C:\ Users \我的名字是Alex \ AppData \ Roaming \ npm \ node_modules \ sails \ node_modules \ waterline \ node_modules \ async \ lib \ async.js:72:13)

     

发送给TestModel的无效属性:    •电子邮件      •"电子邮件"验证规则输入失败:' alex@yahoo.com'

如果我禁用电子邮件验证,一切都很好。

{ email: 'alex@yahoo.com',
  createdAt: '2015-08-08T21:09:25.118Z',
  updatedAt: '2015-08-08T21:09:25.118Z',
  id: 1 }

自己的电子邮件验证方法 - 不是一个好的解决方案。

我尝试过像数据库重新安装这样琐碎的蠢事,但它没有帮助。抱歉我的英文不好,希望我能在这里找到答案。

2 个答案:

答案 0 :(得分:7)

我现在有一个奇怪的解决方案。我将属性类型更改为'email'并删除了email: true类型。

module.exports = {
  attributes: {
    email: {
      type: 'email',
      required: true,
      unique: true
    }
  }
};

现在它有效。它对我来说没问题,但它没有记录,我仍然想知道为什么默认方式不起作用。

答案 1 :(得分:1)

根据waterline docs

  

验证直接在Collection属性中定义。此外,您可以将属性类型设置为任何支持的Anchor类型,Waterline将构建验证并将架构类型设置为该属性的字符串。

因此,当您设置的类型不是core types水线之一时,将使用它来验证其中一个验证rules supported by Anchor中的类型并将数据保存为字符串

因此,定义这样的模式将起作用:

module.exports = {
  attributes: {
    email: {
      type: 'email',
      required: true,
      unique: true
    }
  }
};
相关问题