here’s my concern:
I have a table A which contains a set of properties including a location property (FYI, no pointers in the table) I have a table B which contains a set of properties and a pointer pointing to a unique object in table A (using the table A objectId property). There may be a same pointer for several objects in table B. So basically, each object in table A has several objects pointing to it from table B.
What I’m trying to achieve is to filter all elements from table A within a certain location using: (please note generic names in the code examples)
let queryA = PFQuery(className: "tableA")
queryA.whereKey("location", nearGeoPoint: location, withinMiles: 5)
which works fine, and then to get all elements from table B pointing to the filtered elements .. and here is a first problem, because table A has no pointers, there seem to be no way to achieve this directly from table A, is there ?
So what I’ve tried is start filtering all objects in table B according to the filtered objects from table A, which led me to:
// Filtering all objects in table A according to a specific PFGeoPoint.
let queryA = PFQuery(className: "tableA")
queryA.whereKey("location", nearGeoPoint: location, withinMiles: 5)
// Filtering all elements in table B according to filtered elements from table A
let queryB = PFQuery(className: "tableB")
queryB.includeKey("pointer")
queryB.whereKey("pointer", matchesKey: "objectId", in: queryA)
// and then fetch the objects
queryB.findObjectsInBackground() { objects, error in
print(objects)
}
which doesn’t work because it seems that matchesKey must be operating under the same class.
I’ve then tried to find all objects from table A within a certain location using queryA and use a for-loop to iterate through the result of the method findObjectsInBackground with Block — [PFObject] — and at each iteration running another findObjectsInBackground using objectId from each PFObject element and passing it to queryB using whereKey and a
PFObject(withoutDataWithClassName: <>, objectId: <>)
which works but leads to asynchronous problems and doesn’t seem quite proper to me.
Any ideas ?
Thanks.
First, make sure to model the relationship between tableB and tableA objects by assigning a relation to tableA (not an objectId) to tableB. In other words...
With that, you'll be able to make the relational query using
whereKey:matchesQuery:...