Okay so I have a view where I need to show all the posts by a business near the user's location. The way my database is set up is such that there is a "BusinessPost" class that contains, among other things, a pointer to my "Businesses" class, so that each post has an owner.
When I'm trying to write the query for my view, I can't seem to figure out how to only get the posts from the user's current location. I can get all the posts from every business, or I can get every business in the user's location, but I can't figure out a way to combine the two in order to get just the posts that came from businesses near where the user is.
My thinking was to first get all the businesses near the user's location, and then make a second query using the "inQuery" argument, to find all the posts that had a pointer reference to a business near the user's location that was gotten in the first query.
However, this won't work, and I've been stuck on this for a couple of days. Does anyone have any suggestions? Help would be greatly appreciated.
getPostsFromLocatedBusinesses.whereKey("Businesses", matchesKey: "objectId", inQuery: getBusinessesInLocation)
EDIT 1: Okay so i rewrote it according to what you suggested and came up with the following, but it still doesn't produce any results:
override func queryForTable() -> PFQuery! {
var getPosts = PFQuery(className: self.parseClassName)
var getBusinesses = PFQuery(className: "Businesses")
if locationUpdated == false {
return nil
}
else {
getBusinesses.whereKey("City", equalTo: self.city)
getBusinesses.whereKey("State", equalTo: self.state)
getPosts.whereKey("Business", matchesQuery: getBusinesses)
getPosts.includeKey("Business")
self.tableView.hidden = false
self.tableView.reloadData()
return getPosts
}
}