views:

144

answers:

2

Hey folks!

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/zvonpd.png

Thanks, Dan

+1  A: 

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.

TechZen
+1  A: 

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.

gerry3
This worked perfect for me. Thanks a lot :)
Daniel