2

在交易表中的属性:

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

我必须写什么谓词查询,有人可以帮助我吗?

问候

4

1 回答 1

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];

并使用 Key-Value Coding 获取相关资产:

NSArray *assets = [deals valueForKeyPath:@"dealsassets.@distinctUnionOfSets.self"]
于 2013-06-21T12:56:42.353 回答