Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ended up going with this for anyone interested</p> <pre><code>-(BOOL)ordersAreSaneOnDay:(NSNumber*)dayNumber forUser:(User*)user inContext:(NSManagedObjectContext*)context { NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"BasicEntry" inManagedObjectContext:context]; [fetchRequest setEntity:entity]; [fetchRequest setResultType:NSDictionaryResultType]; NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(status == %@) &amp;&amp; ((type != %@) &amp;&amp; (type != %@) &amp;&amp; (dayNumber == %@)) &amp;&amp; ((user == NIL) || (user == %@))",[NSNumber numberWithInt:EntryStatusAlive],[NSNumber numberWithInt:EntryTypeTask],[NSNumber numberWithInt:EntryTypeCompletedTask],dayNumber,user]; [fetchRequest setPredicate:predicate]; NSExpression *keyPathExpression = [NSExpression expressionForKeyPath: @"order"]; // Does not really matter NSExpression *maxExpression = [NSExpression expressionForFunction: @"count:" arguments: [NSArray arrayWithObject:keyPathExpression]]; NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init]; [expressionDescription setName: @"orderCount"]; [expressionDescription setExpression: maxExpression]; [expressionDescription setExpressionResultType: NSInteger32AttributeType]; [fetchRequest setPropertiesToFetch: [NSArray arrayWithObjects:expressionDescription,@"order",nil]]; [expressionDescription release]; [fetchRequest setPropertiesToGroupBy:[NSArray arrayWithObjects:@"order",nil]]; //[fetchRequest setHavingPredicate:[NSPredicate predicateWithFormat:@"self.order.@count &gt; 1"]]; //[fetchRequest setHavingPredicate:[NSComparisonPredicate predicateWithLeftExpression:maxExpression rightExpression:[NSExpression expressionForConstantValue:[NSNumber numberWithInteger:1]] modifier:NSDirectPredicateModifier type:NSGreaterThanPredicateOperatorType options:NSCaseInsensitivePredicateOption]]; NSError *error; NSArray * array = [context executeFetchRequest:fetchRequest error:&amp;error]; array = [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"orderCount &gt; 1"]]; //NSLog(@"it worked %@",array); [fetchRequest release]; if ([array count]) return FALSE; return TRUE; </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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