问题
I have two entity: A and B. Every element of A can have more elements of B (one to many).
Now I have an item of A and I would to take, in this item, one item B (contained in A) that it has B.field = "myParameter".
How can I generate the Predicate for this?
回答1:
You may be looking for that (tested with MagicalRecord):
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(field LIKE %@) AND (isLinkedToAObject == %@)", myFieldParameter, objectA];
With:
ClassB
has a property isLinkedToAObject
to link it to ClassA
.
来源:https://stackoverflow.com/questions/25930232/coredata-predicate-for-one-to-many-relationship