loopbackjs - 环回更新模型扩展自用户模型错误
问题描述
我创建了一个以 User 作为基础模型的 Artist 模型。我试图通过 Loopback 资源管理器更新艺术家模型,但出现错误:
“消息”:“ValidationError:
Artist
实例无效。详细信息:password
不能为空白(值:未定义);
我已经注册了一个示例信息,并且我在 MongoDB 的艺术家数据库中有它。我不知道为什么我只是想更新现有数据时需要在电子邮件和密码字段中输入一些内容?
这是我的艺术家 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": {}
}
我在这里错过了什么吗?
解决方案
因为您的实体是从User模型继承的,所以在使用POST或PUT方法时需要设置“密码”和“电子邮件”属性(因此创建/更新整个对象) - 因为它们用于登录用户.
如果您只是想在不传递整个数据的情况下更新您的艺术家,请使用PATCH。(然后'密码'和'电子邮件'将不再是强制性的)。
如果您不需要使用 Loopback 的登录系统,请不要从User模型继承您的实体。(或者你还有其他理由这样做吗?)
推荐阅读
- browserstack - Browserstack:只有一个操作系统选项。iOS设备?
- swift - CTFontCreatePathForGlyph 创建的文本路径被翻转
- python - 为什么在浏览器的网页中看到 {%extends %} , {%block body_block%},{%endblock%} ?
- api - 如何通过 (Z3) API 指定 smt.string_solver=z3str3?
- jquery - 我在用我的 html 代码制作带有嵌套类的 JSON 时遇到问题
- sql-server - 我有一个包含 1500 个左右表的 SQL Server 数据库。是否有一种快速方法可以在一个查询中确定每个表中每一列的最大值?
- asp.net-mvc - 无法从子 web.config 读取
- c# - Winforms 中的简单相机捕捉
- uart - **STM32f427 UART with DMA** 从控制台接收数据时最高位有时为1
- arrays - 如何在javascript变量中捕获多个嵌套的文档数组作为mongodb查询的结果