我有一个模仿具有以下结构的数据库表Entity:CoreDataMySQL
Photo
abv Double
photoId Integer16
photographer String
isActive Boolean
lastUpdated Data
name String
我可以运行以下SQL语句来获得我想要的结果集:
SELECT `photographerName`, COUNT(`photographerName`)
FROM `Photos`
WHERE `isActive` LIKE 1
GROUP BY `photographerName`
ORDER BY `photographerName`
我可以使用什么组合NSFetchRequest来获得相同的NSSortDescriptor结果?NSPredicateNSExpressionDescriptioniOS
我正在使用以下内容:
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Photo"];
NSSortDescriptor *photographerSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"photographer" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)];
NSPredicate *onlyActivePhotos = [NSPredicate predicateWithFormat:@"isActive == 1"];
request.sortDescriptors = @[photographerSortDescriptor];
request.predicate = onlyActivePhotos;
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
这让我得到isActive罚款,但为每个返回一行Photo,而不是Photographer.
或者......我应该把它分成两部分Entities吗?例如,与?Photographer具有一对多关系。Photos