mfaani
mfaani

Reputation: 36427

How can I create multiple relationships between the same entities in Coredata?

I've read here but told to open a new question.

I have CountryEntity. It has two relations.

How I should set the inverse part. Apparently only either capital or cities can have a relation with the CountryEntity.

Current issue:

enter image description here

Upvotes: 1

Views: 215

Answers (1)

Tom Harrington
Tom Harrington

Reputation: 70976

You just... create the relationships, and give each one an inverse relationship. No special steps are needed. From your description,

  • capital would have a to-one inverse called something like capitalOf, to indicate which CountyEntity the CityEntity is capital of. If a city is not the capital, the value of the relationship would be nil.
  • cities would have a to-one inverse called something like county to indicate that the CityEntity is in the CountyEntity. This would never have a nil value.

Apparently only either capital or cities can have a relation with the CountryEntity

This isn't true, or at least it's not required by Core Data.

Upvotes: 1

Related Questions