Suppose I have a set of PFObjects (essentially dictionaries) of class "myObject". Objects of this class contain for key "myDictionary" a dictionary. "myDictionary", in turn, has a key "myKey" that I want to access and search for matches against "mySearchTerm". I don't want to download all myObject objects and then iterate through them to check myKey in each, because that would be very inefficient. I want to use a findObjects
message to return just the matches.
Is such a query possible? In other words, how can I search the values in a dictionary that is assigned to a key for a PFObject without downloading all PFObjects of that class?
Here's what it might look like if there were a simple method for it, but I made up the containsKey part to clarify what I am contemplating:
PFQuery *objectQuery = [PFQuery queryWithClassName:@"myObject"];
[objectQuery whereKey:@"myDictionary" ~containsKey~:@"myKey" equalTo:"mySearchTerm"];
It appears the best way to do it is by making myDictionary a PFObject in its own right (so instantiate it as PFObject* instead of NSMutableDictionary*). Then I can query it and then, in a second query, retrieve the parent PFObjects for the matches.
PFQuery *myDictionaryQuery = [PFQuery queryWithClassName:@"myDictionary"];
[myDictionaryQuery whereKey:@"myKey" equalTo:mySearchTerm];
PFQuery *myObjectQuery = [PFQuery queryWithClassName:@"myObject"];
[myObjectQuery includeKey:@"myDictionary"];
[myObjectQuery whereKey:@"myDictionary" matchesQuery:myDictionaryQuery];