41

In an almost identical situation to Core Data - Fetch all objects NOT in a relationship, only I'm looking for all records of one type that are not in any to-many relationship with another type.

So let's say I've got a set of patients, and a set of lists. Patients can belong to multiple lists, and a list can contain multiple patients.

How do I find all of the patients that aren't on any list? I'm using a Core Data model.

grg
  • 5,023
  • 3
  • 34
  • 50
bryanjclark
  • 6,247
  • 2
  • 35
  • 68

1 Answers1

11

Figured it out. Here's what I did:

NSPredicate *predicate = [NSPredicate
                          predicateWithFormat:@"lists.@count == 0"];
[fetchRequest setPredicate:predicate];

Then when I ran the fetch request, it only brought up the patients with no list attached.

bryanjclark
  • 6,247
  • 2
  • 35
  • 68