Core Data Many-to-Many Relationship NSPredicate

后端 未结 1 737
暖寄归人
暖寄归人 2020-12-20 06:38

I have a data model with a many-to-many relationship like EntityA <-->> EntityB <<--> EntityC. I used to query EntityA with diffe

相关标签:
1条回答
  • 2020-12-20 07:24

    (I had a lot of trouble puzzling out your predicate so take this with a grain of salt.)

    I think your making this overly complicated. You should simplify with keypaths. Each EntityB has a to-one relationship to a EntityC so to search on EntityB objects all you need to do is check EntityB.entityCRelationshipName.entityCAttribute. So something like:

    ALL B.EntityC.name like %@
    

    In any case, (if I'm reading the predicate correctly) this:

    SUBQUERY($B.EntityC, $EntityC, $EntityC.name like %@)
    

    can only return a single object instead of a collection. Therefore, the predicate will not be able to perform a count on it. That is what your error message means.

    I suggest using the predicate editor in the Data Model editor to hash out the predicates before you store them.

    0 讨论(0)
提交回复
热议问题