Search code examples
swiftparse-platformpfquery

Swift & Parse: Query Results Where Column Class Is Equal To A Column In Users Class


I have searched far and wide for an answer to this. In written English I'm trying to do the following:

Query results where the column "WorkGroup" in the "Issues" class is equal to the column "WorkGroup" in the "Users" class.

I tried countless things including; NotContainedIn, ObjectForKey, wherekey (matchesquery), includeKey, add pointers, etc.

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.

Solution

  • 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: