斯威夫特&解析:查询结果列类等于用户类中的列

时间:2018-03-01 23:13:12

标签: swift parse-platform pfquery

我已经广泛搜索了这个答案。用书面英语我试着做以下几点:

查询结果,其中“Issues”类中的“WorkGroup”列等于“Users”类中的“WorkGroup”列。

我尝试了无数的事情,包括; NotContainedIn,ObjectForKey,wherekey(matchesquery),includeKey,add pointers等。

let query = PFQuery(className: ISSUES_CLASS_NAME)
let now = Date()

query.whereKey(ISSUES_SUB_DATE, lessThanOrEqualTo: now)
query.whereKey(ISSUES_STATUS, notEqualTo: "Closed")
query.order(byDescending: ISSUES_SUB_DATE)

// Add Where Issues WorkGroup value = Users WorkGroup value.

2 个答案:

答案 0 :(得分:1)

let userQuery = PFUser.query();
// Set up user query
let issueQuery = PFQuery(className:"Issue");
issueQuery.whereKey("WorkGroup", matchesKey:"WorkGroup", inQuery:userQuery);

http://parseplatform.org/Parse-SDK-iOS-OSX/api/Classes/PFQuery.html#/c:objc(cs)PFQuery(im)whereKey:matchesKey:inQuery

答案 1 :(得分:0)

试试这个

func yes(){
    let query = PFUser.query()
    query?.findObjectsInBackground(block: { (objects: [PFObject]?, error: Error?) in
        if error == nil{
            for object in objects!{
                self.array.insert(object.object(forKey: WorkGroup) as! String, at: 0)
                let dataQuery = PFQuery(className: "Issues")
                dataQuery.whereKey(WorkGroup, containedIn: self.array)
                dataQuery.findObjectsInBackground(block: { (objects: [PFObject]?, error: Error?) in
                    if error == nil{
                        for object in objects!{
                        }
                    }
                })
            }
        }
    })
}

仔细检查括号