环回更新模型源自用户模型错误

时间:2018-08-10 09:26:37

标签: loopbackjs loopback

我已经创建了一个基于User的Artist模型。我试图通过Loopback资源管理器更新艺术家模型,但出现错误:

  

“ message”:“ ValidationError:Artist实例无效。详细信息:password   不能为空(值:未定义); email不能为空(值:   未定义)。

我已经注册了一个样本信息,并将其保存在MongoDB的我的艺术家数据库中。我不确定为什么仅在尝试更新现有数据时为什么需要在电子邮件和密码字段中输入内容?

enter image description here

这是我的艺术家JSON:

{
  "name": "Artist",
  "base": "User",
  "idInjection": false,
  "options": {
    "validateUpsert": true,
    "strictObjectIDCoercion": true
  },
  "properties": {
    "firstName": {
      "type": "string"
    },
    "middleName": {
      "type": "string"
    },
    "lastName": {
      "type": "string"
    },
    "telephoneNumber": {
      "type": "string"
    },
    "country": {
      "type": "string"
    },
    "city": {
      "type": "string"
    },
    "genre": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "pricing": {
      "type": "string"
    },
    "profilePicture": {
      "type": "string"
    }
  },
  "validations": [],
  "acls": [
    {
      "accessType": "EXECUTE",
      "principalType": "ROLE",
      "principalId": "$authenticated",
      "permission": "ALLOW",
      "property": "create"
    },
    {
      "accessType": "EXECUTE",
      "principalType": "ROLE",
      "principalId": "$owner",
      "permission": "ALLOW",
      "property": [
        "updateAttributes",
        "deleteById"
      ]
    },
    {
      "accessType": "READ",
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "ALLOW"
    }
  ],

  "methods": {}
}

我在这里想念什么吗?

1 个答案:

答案 0 :(得分:2)

由于您的实体是从 User 模型继承的,因此在使用时需要设置“ 密码”和“ 电子邮件”属性 POST PUT 方法(以便创建/更新整个对象)-用于登录用户。

如果您只是想在不传递全部数据的情况下更新Artist,请使用 PATCH 。 (然后,<< em>密码”和“ 电子邮件”将不再是必需的。)

如果您不需要使用Loopback的登录系统,请不要从 User 模型继承您的实体。 (或者您还有其他理由这样做吗?)

相关问题