Rest “失踪”;“目标”;来自关系字段
我通过REST使用Parse Server作为移动应用程序的后端。当我试图建立对象之间的关系时,似乎出现了一些问题 响应对象的关系字段中缺少对象ID 复制步骤Rest “失踪”;“目标”;来自关系字段,rest,parse-server,Rest,Parse Server,我通过REST使用Parse Server作为移动应用程序的后端。当我试图建立对象之间的关系时,似乎出现了一些问题 响应对象的关系字段中缺少对象ID 复制步骤 报名 curl -X "POST" ".../api/users" \ -H "X-Parse-Revocable-Session: 1" \ -H "X-Parse-REST-API-Key: MyKey" \ -H "X-Parse-Application-Id: MyAppID" \ -H "
curl -X "POST" ".../api/users" \
-H "X-Parse-Revocable-Session: 1" \
-H "X-Parse-REST-API-Key: MyKey" \
-H "X-Parse-Application-Id: MyAppID" \
-H "Content-Type: application/json" \
-d $'{
"username": "username",
"password": "password"
}'
curl -X "POST" ".../api/classes/session" \
-H "X-Parse-REST-API-Key: MyKey" \
-H "X-Parse-Application-Id: MyAppID" \
-H "Content-Type: application/json" \
-d $'{
"title": "Session",
"owner": {
"objects": [
{
"__type": "Pointer",
"className": "_User",
"objectId": "RegisteredUserID"
}
],
"__op": "AddRelation"
}
}'
curl ".../api/classes/session" \
-H "X-Parse-REST-API-Key: MyKey" \
-H "X-Parse-Application-Id: MyAppID"
结果[0]。所有者
包含objectId
{
"results": [
{
"objectId": "xdTAyg6NXY",
"title": "Session",
"createdAt": "2017-04-22T21:20:08.657Z",
"updatedAt": "2017-04-22T21:20:08.657Z",
"owner": {
"__type": "Relation",
"className": "_User"
"objectId": "RegisteredUserID"
}
}
]
}
{
"results": [
{
"objectId": "xdTAyg6NXY",
"title": "Session",
"createdAt": "2017-04-22T21:20:08.657Z",
"updatedAt": "2017-04-22T21:20:08.657Z",
"owner": {
"__type": "Relation",
"className": "_User"
}
}
]
}
实际结果
结果[0]。所有者
不包含objectId
{
"results": [
{
"objectId": "xdTAyg6NXY",
"title": "Session",
"createdAt": "2017-04-22T21:20:08.657Z",
"updatedAt": "2017-04-22T21:20:08.657Z",
"owner": {
"__type": "Relation",
"className": "_User"
"objectId": "RegisteredUserID"
}
}
]
}
{
"results": [
{
"objectId": "xdTAyg6NXY",
"title": "Session",
"createdAt": "2017-04-22T21:20:08.657Z",
"updatedAt": "2017-04-22T21:20:08.657Z",
"owner": {
"__type": "Relation",
"className": "_User"
}
}
]
}
按所有者id请求会话会产生与上面“获取所有会话”相同的响应。即使包含include=owner
查询参数,也会有相同的响应。
获取用户的会话:
curl ".../api/classes/session?include=owner&where=%7B%22owner%22:%7B%22__type%22:%22Pointer%22,%22className%22:%22_User%22,%22objectId%22:%RegisteredUserID%22%7D%7D" \
-H "X-Parse-REST-API-Key: MyKey" \
-H "X-Parse-Application-Id: MyAppID"
此外,Parse Dashboard会正确处理点击关系
环境设置
- 服务器
- 解析服务器版本:2.3.8
- 操作系统:macOS Sierra
- 硬件:MacBookPro
- 服务器:本地主机
- 数据库
- MongoDB版本:3.4.3
- 存储引擎:wiredTiger
- 硬件:MacBookPro
- 服务器:本地主机
curl -X "POST" ".../api/classes/session" \
-H "X-Parse-REST-API-Key: MyKey" \
-H "X-Parse-Application-Id: MyAppID" \
-H "Content-Type: application/json" \
-d $'{
"title": "Session",
"owner": {
"__type": "Pointer",
"className": "_User",
"objectId": "RegisteredUserID"
}
}'
谢谢你的编辑,Alexandru。似乎我不明白卷曲格式是如何工作的。因为它们中的一些不使用4个空格进行格式化。