views:

54

answers:

0

I am currently trying to setup a NSFetchedResultsController that will order my table view based on the number of entities in a to-many relationship. I am not sure if this makes a difference when counting, but this is also an inverse relationship.

I thought something like this would work just fine:

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Parent"
inManagedObjectContext:managedObjectContext];

NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] 
initWithKey:@"children.@count" ascending:YES];

NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1,
nil];

[fetchRequest setSortDescriptors:sortDescriptors];

I keep getting 'Keypath containing KVC aggregate where there shouldn't be one; failed to handle children.@count'.

Any ideas on what could be going wrong?