解析服务器关系查询不起作用

时间:2017-02-07 10:09:37

标签: swift database relational-database parse-server

我在解析服务器中有两个类_UserOrganization,在User我有关系列organization类型

"organization": {
    "__type": "Relation",
    "className": "Organization"
},

我使用swift 3从Users类查询我的用户,我希望包含(加入)与每个用户相关的所有组织,所以我尝试了

let innerQuery = PFQuery(className: "Organization")
let query = PFQuery(className: "_User")
query.whereKey("organization", matchesQuery: innerQuery)
query.findObjectsInBackground {  }

但是这段代码给了我错误

这是查询

{
    "limit": "1500",
    "where": {
        "organization": {
            "$inQuery": {
                "className": "Organization"
            }
        }
    },
    "_method": "GET"
}

和结果。

{
    "code": 102,
    "error": "improper usage of $inQuery"
}

为什么这不起作用?

1 个答案:

答案 0 :(得分:0)

你可以这样试试:

let query = PFQuery(className: "Organization")
    query.whereKey("organization", equalTo: PFObject(withoutDataWithClassName:"_User", objectId:PFUser.currentUser()!))
    query.findObjectsInBackground { (objects, error)-> Void in