在交易表中的属性:
ispopular(attribute)
groupname(attribute)
dealsassets(relationship-name to assets)
在资产表中,属性为:
assettype(attribute)
caption(attribute)
dealassetid(attribute)
assetsdeal(inverse relationshipname to deals)
交易是资产一对多关系&资产交易多对一关系
我想写一个我需要的查询ispopular == 1 then that related field's assets.dealasseti
,
我必须写什么谓词查询,有人可以帮助我。
问候
答案 0 :(得分:3)
这是你在找什么?
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];
并使用键值编码获取相关资产:
NSArray *assets = [deals valueForKeyPath:@"dealsassets.@distinctUnionOfSets.self"]