I am having some issue with understanding of Core Data. In my program there are two entities, say A
and B
. They have both references on each other and A
has a to-many relationship to B
.
I can have them displayed in TableViewControllers and I can display all A
s and all B
s. However, I want to only display all B
s that belong开发者_如何学C to a specific A
, so I'd like to know the Core Data version of a where
clause. As there are no foreign keys in Core Data, I guess it needs to go via the relationship, right?
I tried it with this:
NSPredicate *predicate = nil;
predicate = [NSPredicate predicateWithFormat:@"readingEntity.meter=%@",meter];
(in the function that I get all B
s, meter is my A
).
Anybody out there who can help me on this one? Regards.
You don't need a predicate at all if you already have an A
object. Instead, you just ask the A
object for its related B
objects.
Don't think of Core Data as SQL. It's not. It works differently.
精彩评论