开发者

Core Data: Finding Related Objects

开发者 https://www.devze.com 2023-03-02 20:04 出处:网络
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 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 As and all Bs. However, I want to only display all Bs 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 Bs, 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消