Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From your question and the comments I <strong>guess</strong> that you want</p> <pre><code>[NSPredicate predicateWithFormat:@"mode = 0 AND (ALL enrollments.mode = 0)"] </code></pre> <p><strong>UPDATE</strong></p> <p>It seems that the ALL aggregate does not work. It throws </p> <pre><code>'NSInvalidArgumentException', reason: 'Unsupported predicate (null)' </code></pre> <p>as @yunas noticed. This has also been noticed previously, e.g.</p> <ul> <li><a href="https://stackoverflow.com/questions/1164338/core-data-nspredicate-and-to-many-key">Core Data, NSPredicate and to-many key</a></li> <li><a href="https://stackoverflow.com/questions/5922139/crash-using-aggregate-operation-all-in-a-core-data-ios-application">Crash using Aggregate Operation: &quot;ALL&quot; in a Core Data iOS Application</a></li> </ul> <p>On the other hand, the ANY aggregate works just fine. So as a <strong>WORKAROUND</strong>, one can replace ALL with an equivalent ANY expression:</p> <pre><code>[NSPredicate predicateWithFormat:@"mode = 0 AND NOT(ANY enrollments.mode != 0)"]; </code></pre> <p>And this actually works (I have tested it)!</p> <p><strong>UPDATE 2</strong></p> <p>During the discussion it has become clear that yunas wants to display a table with one row for each group with mode=0, and within the table row display all enrollments of that group with mode=0.</p> <p><em>First solution (probably the better one):</em> Find all admissible groups first with the method given above. For each row (in <code>cellForRowAtIndexPath:</code>) filter the enrollments for that group and draw the cell.</p> <p><em>Second solution:</em> Fetch all enrollments and sort them by group. This requires only one fetch request, but the result is not so suitable as table view data source. The fetch request would look like this:</p> <pre><code>NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Enrollment"]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"mode = 0 AND group.mode = 0"]; request.predicate = predicate; NSSortDescriptor *sort1 = [NSSortDescriptor sortDescriptorWithKey:@"group.name" ascending:YES]; NSSortDescriptor *sort2 = [NSSortDescriptor sortDescriptorWithKey:@"share" ascending:YES]; request.sortDescriptors = [NSArray arrayWithObjects:sort1, sort2, nil]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload