user281300
user281300

Reputation: 1457

Coredata relationship entity creation

I have a question about the coredata relationship.

Essentially, if I have 1 entity called i.e parent and the other entity which it has a relationship with is children and it is inverse.

If I create the parent entity, will it create the children entity as well? I 've set the "parentchildrenrelationship" to optional but it looks like every time I create the parent entity, it creates the children entity.

Is that something normal ? Thanks

Upvotes: 0

Views: 177

Answers (2)

Sean Freitag
Sean Freitag

Reputation: 920

It is not normal. Are you sure you're not creating the children entity otherwise? Just because you create one entity does not mean it creates the entities that it is referencing.

Upvotes: 1

Tim
Tim

Reputation: 60150

Core Data should not automatically create entities to fulfill relationships, especially if the relationship is optional. The value of children should either be nil (for a one-to-one relationship) or an empty NSSet or NSArray (for a one-to-many relationship, depending on ordering) for a newly created parent entity.

Upvotes: 1

Related Questions