ios NSFetchRequest,对子对象进行排序
|
嗨,我想知道如何指定FetchRequest,以便可以在关系中对对象进行排序。
| Parent | | Child |
| - name |------->| - name |
| - position | | - position |
例如,如果我有一个包含位置属性的父表,并且与一个也具有位置属性的子表具有一对多关系。如何返回包含按位置排序的子对象的父对象(按位置排序)。
例如
parent 1
child 1
child 2
child 3
parent 2
child 15
child 16
parent 3
child 22
child 23
child 24
显然,以下代码将正确排序父对象,但是如何使随每个父对象返回的子对象的顺序正确
NSFetchRequest* fetchReqest = [[NSFetchRequest alloc] init];
NSEntityDescription* entity = [NSEntityDescription entityForName:@\"parent\" inManagedObjectContext:managedObjectContext];
[fetchReqest setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
initWithKey:@\"position\" ascending:YES];
[fetchReqest setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];
NSArray* parentsThatContainChildren = [managedObjectContext executeFetchRequest:fetchReqest error:nil];
干杯
没有找到相关结果
已邀请:
1 个回复
梦话快家腹