Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 核心数据:对多个关系进行谓词,以获取多个相关表中的对象_Iphone_Objective C_Core Data - Fatal编程技术网

Iphone 核心数据:对多个关系进行谓词,以获取多个相关表中的对象

Iphone 核心数据:对多个关系进行谓词,以获取多个相关表中的对象,iphone,objective-c,core-data,Iphone,Objective C,Core Data,在表中,属性包括: ispopular(attribute) groupname(attribute) dealsassets(relationship-name to assets) 在资产表中,属性为: assettype(attribute) caption(attribute) dealassetid(attribute) assetsdeal(inverse relationshipname to deals) 交易是资产一对多关系&资产对交易多对一关系 我想写一个查询,其中我需要

在表中,属性包括:

ispopular(attribute)
groupname(attribute)
dealsassets(relationship-name to assets)
在资产表中,属性为:

assettype(attribute)
caption(attribute)
dealassetid(attribute)
assetsdeal(inverse relationshipname to deals)
交易是资产一对多关系&资产对交易多对一关系

我想写一个查询,其中我需要的是
ispopular==1,然后是相关字段的资产。dealasseti

我要写什么谓词查询,有人能帮我吗


这就是你要找的吗

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”的交易:

并使用键值编码获取相关资产:

NSArray *assets = [deals valueForKeyPath:@"dealsassets.@distinctUnionOfSets.self"]

哦,我不知道!Thanks@Firo:“=”和“=”都可以工作。但是,如果您记录一个谓词,则会为相等运算符显示“==”,因此我倾向于使用它。@iOSDev:您说过资产实体与交易有关系“AssetDeal”,交易有一个属性“ispopular”。也许您可以显示Assets.h和Deals.h的内容,或者显示核心数据属性的屏幕截图。-这与HTTP有什么关系呢???@iOSDev:模型看起来不错。但可能是你在使用StackMob吗?如果是,你为什么不在你的问题中告诉我们我没有使用StackMob的经验,但根据以下回答:,不支持在关系的属性上获取。@iOSDev:所以您只需要资产ID列表?请尝试
[dealsvalueforkeypath:@“dealsassets@distinctUnionOfSets.dealassetid”]
NSArray *assets = [deals valueForKeyPath:@"dealsassets.@distinctUnionOfSets.self"]