次の構造のデータベーステーブルをEntity模倣CoreDataするシングルがあります。MySQL
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、同じ結果NSPredicateをNSExpressionDescription得ることができiOSますか?
私は以下を使用しています:
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、すべての行が返されます。PhotoPhotographer
または...これを2つに分割する必要がありEntitiesますか?たとえば、?Photographerと1対多の関係があります。Photos