开发者

Objective-C : Relationship to own class (CoreData)

In my project there is a managed object called "Group".

This object itself can contain child group objects.

How do I solve this situation in CoreData and in the FetchedResultsController?

My first shot:

http://i46.tinypic.com/zvonp开发者_高级运维d.png

Thanks, Dan


I would make two separate relationships that are inverses of each other.

Group has a to-many relationship with Group named "children", Group also has a to-many relationship with Group named "parents" and they are inverses of each other.

Or, if your data model only calls for one parent: Group has a to-many relationship with Group named "children", Group also has a to-one relationship with Group named "parent" and they are inverses of each other.


It looks correct. Usually you term the other entities children instead of parents but that is just a matter of style and convention.

You would fetch the child/parent relationship just as you would any other attribute. The only gotcha is that each relationship attribute is returned as a NSSet so you have to find the child you want inside of the set.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜