这是你想要的?
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Assets"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"assetsdeal.ispopular == 1"];
[request setPredicate:predicate];
NSError *error;
NSArray *result = [context executeFetchRequest:request error:&error];
使用反向关系,您要求相关交易具有“ispopular == 1”属性的所有资产。
替代解决方案(如果第一个由于某些 StackMob 限制而不起作用):首先获取具有“ispopular == 1”的交易:
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Deals"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ispopular == 1"];
[request setPredicate:predicate];
NSError *error;
NSArray *deals = [context executeFetchRequest:request error:&error];
并使用 Key-Value Coding 获取相关资产:
NSArray *assets = [deals valueForKeyPath:@"dealsassets.@distinctUnionOfSets.self"]