ADude
ADude

Reputation: 345

Core Data Relationships on Abstract Entities

Is it legitimate to create a one to one relationship between two entities when one is set to be abstract ?

Upvotes: 2

Views: 3776

Answers (2)

Alladinian
Alladinian

Reputation: 35706

An abstract entity is not meant to be instantiated. That's why you cannot create such a relationship. What you could do though is to create a relationship where the entity(s) are inheriting from an abstract entity.

From Apple's docs:

A relationship specifies the entity, or the parent entity, of the objects at the destination. This can be the same as the entity at the source (a reflexive relationship). Relationships do not have to be homogeneous. If the Employee entity has two sub-entities, say Manager and Flunky, then a given department's employees may be made up of Employees (assuming Employee is not an abstract entity), Managers, Flunkies, or any combination thereof.

EDIT: Apparently you could create such a relationship (so that child entities would inherit the relationship as well)...

If you define an entity inheritance hierarchy (see “Entity Inheritance”), when you specify a super-entity as the entity for a fetch request, the request returns all matching instances of the super-entity and of sub-entities. In some applications, you might specify a super-entity as being abstract (see “Abstract Entities”). To fetch matching instances of all concrete sub-entities of the abstract entity, you set the entity for fetch specification to be the abstract entity. In the case of the domain described in “Abstract Entities,” if you specify a fetch request with the Graphic entity, the fetch returns matching instances of Circle, TextArea, and Line.

See also this answer: Core Data: Abstract Entity in Fetch Request

Upvotes: 3

Paul de Lange
Paul de Lange

Reputation: 10633

yes. you can have a person who owns a "thing"...

Upvotes: 1

Related Questions