0

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.

2 Answers 2

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:

Sign up to request clarification or add additional context in comments.

1 Comment

omg! I cant thank you enough for this man. This is exactly what i wanted and it works like a charm. Thank you!
0

Try this

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!{
                        }
                    }
                })
            }
        }
    })
}

Double check the brackets

6 Comments

It might work but it's inefficient and there's a built in method to Parse Queries for this.
@JakeT. this does work but you example is much cleaner and probably runs smoother
thanks for answer Jared, i bet it took forever to write that out, i appreciate it!
@klykins thanks for the question haha this revolutionized all of my swift code lol
@JaradKears hah, beauty of SO. Even when you come to leave an answer, you may wind up learning something new yourself. If your answer collected all of the WorkGroup objects from the first query into a single array and queried for them all at once, it wouldn't perform that much worse than the matchesKey:InQuery method, aside from the extra time waiting for the server to pass back data, but using that method definitely makes it far cleaner! This is one of the methods I wish I discovered early in my parse usage, and I unfortunately did not.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.