2

I want to create a PFQuery for a PFRelation to find objects where the specified relation has zero objects in it. Here's what I've tried:

PFQuery *categoryQuery = [CatalogCategory query];
[categoryQuery whereKeyDoesNotExist:@"subcategories"];

But I get an error saying I can't use this operator on a PFRelation key. How else could I achieve what I'm looking for?

Cory Imdieke
  • 14,140
  • 8
  • 36
  • 46
  • From what I understand you would use a PFRelation query after getting the objects first, just like you can't save a relation to an object that hasn't been saved first. Something like `PFRelation *relation = [yourObjectInstanceHere relationforKey:@"subcategories"]` – soulshined Aug 17 '15 at 16:14
  • Yeah but I don't have an objectInstance to start with. I'm searching for objects that don't have any subcategories, so my starting point is "all objects". I don't know if that makes sense or not. – Cory Imdieke Aug 17 '15 at 16:17
  • Exactly, so you find all the objects first (without parameters) or not, then do a PFRelation query : see here: https://www.parse.com/docs/ios/guide#relations-using-parse-relations second topic – soulshined Aug 17 '15 at 16:28

1 Answers1

0

Have you tried [categoryQuery whereKey:@"subcategories" equalTo:nil]?

It may be that the whereKeyDoesNotExist: method is unavailable for objects of the PFRelation type.

Ryan Kreager
  • 3,571
  • 1
  • 20
  • 35
  • Well, whereKey:equalTo: must have a non-nil object passed to it. So, that won't work. It does seem like the obvious solution though, doesn't it. – Cory Imdieke Aug 17 '15 at 16:38