有什么更好的方法来构建NSPredicate与一对多的深层关系? [英] What's better way to build NSPredicate with to-many deep relationships?

查看:120
本文介绍了有什么更好的方法来构建NSPredicate与一对多的深层关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个实体:EntityA,EntityB和EntityC与多对多关系连接。

I have three entities: EntityA, EntityB and EntityC connected with to-many relationships.

有关详细信息,请参阅架构:

See schema for details:

对于获取依赖于EntityB.name的EntityA的所有实例,我使用这样的谓词:

For getting all instance of EntityA which depend from EntityB.name I use the predicate like this:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY EntityB.name like 'SomeName'"];

从EntityC.name获取EntityA的所有实例应该是什么谓词?
我尝试查询像 @ANY EntityB.entitiesC.name like'SomeName'但获取异常多对多键不允许在这里

What should be predicate for getting all instance of EntityA which depend from EntityC.name? I tried query like @"ANY EntityB.entitiesC.name like 'SomeName'" but get exception "multiple to-many keys not allowed here".

最好的问候,

b $ b

推荐答案

我的最终解决方案是使用SUBQUERY。

My final solution is to use SUBQUERY.

NSPredicate *p = [NSpredicate predicateWithFormat:@"(name like %@) AND (0 != SUBQUERY(entitiesB, $x, (0 != SUBQUERY($x.entitiesC, $y, $y.name like %@).@count)).@count)", nameA, nameC];

很遗憾,我无法在nsExpression对象上扩展此查询。

Unfortunately I was unable to expand this query on nsExpression objects.

这篇关于有什么更好的方法来构建NSPredicate与一对多的深层关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆