Core Data: NSFetchRequest sorting by count of to-many relationship

Posted by Ben Reeves on Stack Overflow See other posts from Stack Overflow or by Ben Reeves
Published on 2010-03-15T15:27:52Z Indexed on 2010/03/15 15:29 UTC
Read the original article Hit count: 507

Filed under:
|

Say I have an parent entity, each of which have a number of children. I want to get all the parents sorted by their number of children. Something similar to the following pseudo code:

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

[[NSSortDescriptor alloc] initWithKey:@"children.count" ascending:NO];
//Execute request

Is there a way construct a fetch like this using core data?

Thanks, Ben

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about core-data