What's better way to build NSPredicate with to-many deep relationships?

后端 未结 2 2055
名媛妹妹
名媛妹妹 2020-12-14 02:36

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

See schema for details:

alt text http://img706.imageshack.us/img706

2条回答
  •  無奈伤痛
    2020-12-14 03:23

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

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

提交回复
热议问题