在Loopback中更改用户默认验证

nki*_*int 1 validation loopbackjs

我深化发展延伸碱基的环回应用User模型来UserCode进行建模,其中每个用户被识别出的email 一个code字段.

这样用户可以使用相同的电子邮件注册两次但使用不同的代码.

node_modules/loopback/common/models/user.js在第691行看到过:

UserModel.validatesUniquenessOf('email', {message: 'Email already exists'});
Run Code Online (Sandbox Code Playgroud)

我想删除此限制/验证,但当然没有更改环回代码.

我该怎么做?也许在启动脚本中我可以遍历所有验证并删除这个?

Rob*_*pta 5

弄清楚了

在这种情况下,您需要删除User模型设置的默认验证

common/models/userCode.js

module.exports = function(UserCode){
   //Add this line and it will start receiving multiple email.
   delete UserCode.validations.email;
}
Run Code Online (Sandbox Code Playgroud)

您还可以使用该required:true|false属性来使任何默认定义属性成为必需或不需要.

通用/模型/ userCode.json

{
  "name": "UserCode",
  "base": "User",
  "idInjection": true,
  "properties": {
    "password": {
      "type": "string",
      "required": true
    },
    ....
    ....
}
Run Code Online (Sandbox Code Playgroud)