Padin215
Padin215

Reputation: 7484

Core data and n number of entity "Person"

can i have an entity have a to-many relationship to itself?

getting a group list from my server, and it can have n number of names and n number of levels. at the top level, lets say i have:

Scott
Jason

Scott and Jason both have n number of employees under them. Scott has

Bryan
Matt

Bryan and Matt both have n number of employees under them

Jill
Lisa

Jill and Lisa both have n Number of employees under them.

sortive like:

enter image description here

but with n subGroups.

my list can have n levels. it needs to be dynamic.

can i boil it down to:

enter image description here

can i just have one entity, Person, that has many-to-many relationship to itself?

Upvotes: 0

Views: 93

Answers (1)

Martin R
Martin R

Reputation: 539815

Yes, an entity can have a many-to-many relationship to itself. You have to define two to-many relationships, e.g.

  • members as to-many relationship from Person to Person,
  • leaders as to-many relationship from Person to Person,

and set both as inverse relationships of each other.

enter image description here

See also Many-to-Many Relationships in the "Core Data Programming Guide".

Upvotes: 2

Related Questions