1

I am using parse in my app and I want to satisfy the two query and return object without using orQueryWithSubqueries. Here my query to parse code:

func queryToParse(){
    var queryForBlood = PFQuery(className: "Donors")
    queryForBlood.whereKey("BloodGroup", equalTo: bloodGroupTextField.text)
    var queryForCity = PFQuery(className: "Donors")
    queryForCity.whereKey("City", equalTo: citySearchTextField.text)
    var query = PFQuery.orQueryWithSubqueries([queryForCity,])
    query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
        if error == nil {
            self.tableData = objects as NSArray
            println(self.tableData)
            self.tableView.reloadData()
        }
        else
        {
            println(error)
        }
    }
}
5
  • my code only satisfy any one of the key but i want both to satisfy the key value and return objects Commented Jul 15, 2015 at 12:55
  • Do you want the 'and' of the two keys - donors in the specified city with the specified blood group? If so the simply call whereKey twice on the same query with the two different criteria Commented Jul 15, 2015 at 13:24
  • i try this but it returns nothing ...var query = PFQuery(className: "Donors") query.whereKey("BloodGroup", equalTo: bloodGroupTextField.text) query.whereKey("City", equalTo: citySearchTextField.text) query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in if error == nil{ self.tableData = objects as NSArray println(self.tableData) self.tableView.reloadData() } else { println(error) } } } Commented Jul 15, 2015 at 13:53
  • Please improve this question. Present a sample of the data from the data browser that the query should find or not find. Be clear in writing about what you want, which two keys and whether you want records that meet both or either condition. Commented Jul 15, 2015 at 14:22
  • Then perhaps you have no records that match both criteria. Commented Jul 15, 2015 at 21:03

1 Answer 1

2

Instead of creating two separate PFQuery, then you just have to create one. You only need to create several PFQuery when you want to make an OR query.


Your code should look something like this:

func queryToParse(){
    let query = PFQuery(className: "Donors").whereKey("BloodGroup", equalTo: bloodGroupTextField.text).whereKey("City", equalTo: citySearchTextField.text)
    query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
        ...
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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.