缺少" objectId"来自关系领域

时间:2017-04-23 08:38:24

标签: rest parse-server

我通过REST使用Parse Server作为移动应用程序的后端。当我尝试设置对象之间的关系时,似乎出现了问题 响应对象的关系字段中缺少objectId

重现的步骤

  1. 注册

    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"
    }'
    
  2. 创建会话

    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"
    }
    }'
    
  3. 获取所有会话

    curl ".../api/classes/session" \
     -H "X-Parse-REST-API-Key: MyKey" \
     -H "X-Parse-Application-Id: MyAppID"
    
  4. 预期结果

    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可以正确处理关系。

    环境设置

    • 服务器

      • parse-server version:2.3.8
      • 操作系统:macOS Sierra
      • 硬件:MacBook Pro
      • 服务器:localhost
    • 数据库

      • MongoDB版本:3.4.3
      • 存储引擎:wiredTiger
      • 硬件:MacBook Pro
      • 服务器:localhost

1 个答案:

答案 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"
  }
}'