我通过REST使用Parse Server作为移动应用程序的后端。当我尝试设置对象之间的关系时,似乎出现了问题
响应对象的关系字段中缺少objectId
。
注册
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"
results[0].owner
包含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[0].owner
不包含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"
}
}
]
}
按所有者ID发送请求会产生与" Get All Sessions"相同的响应。以上。即使包含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可以正确处理关系。
服务器
数据库
答案 0 :(得分:0)
将其用于创建会话:
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"
}
}'