NSPredicate for to-many relationship, where a relationship (NSSet) must contain Entities defined in an NSArray

后端 未结 1 450
后悔当初
后悔当初 2021-01-23 19:10

Given the following Core Data Model:

-> : to-one releationship  
->>: to-many relationship

Entity A ->> Entity B 
Entity B -> A // each B belo         


        
相关标签:
1条回答
  • 2021-01-23 19:29

    Does

    [NSPredicate predicateWithFormat:@"A==%@ AND (ALL %@ IN Bs)", Ax, myArray];
    

    do what you expect? I am not sure (and away from my OS X box) whether this predicate is translatable to SQL for the Core Data SQLite engine. You may need a SUBQUERY expression:

    [NSPredicate preidcateWithFormat:@"A==%@ and SUBQUERY(Bs, $x, $x IN %@).@count == %d", Ax, myArray, myArray.count];
    

    This assumes that the items in myArray are unique.

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