I am learning Core Data so I was confused about the following.
I need to know how the relationships worked in the inherited scenario.
I have a data model with Entities Zoo, Animal , Dog, Lion.
Dog and Lion have Animal as the parent Entity.
Now Zoo has one to many relationship to animal.
I want to know if Zoo will need to have one to many relationship to animal or it need to have to one to many relationship to Dog and Lion. Will the inheritance work in this case or not. Like in future if I add Tiger, Do I need to add that in Zoo relationship or it will work just fine once I inherit Tiger from Animal.
Inverse relationships enable Core Data to propagate change in both directions when an instance of either the source or destination type changes. Every relationship must have an inverse. When creating relationships in the Graph editor, you add inverse relationships between entities in a single step.
Parent-Child is one of the most common logical relationships between evidence entities. Typically, a parent-child relationship is a one-to-many relationship where: The parent can have many children AND. Each child must belong to a parent.
An entity is represented by an instance of the NSEntityDescription class. This class provides access to a wide range of properties, such as its name, the data model it is defined in, and the name of the class the entity is represented by.
As long as your child entities inherit from the Animal entity, they will also inherit the relationship that the Animal parent entity has with Zoo. It's like class inheritance in OOP, where subclasses inherit variables, methods, etc from their superclasses automatically.
So all you need to do is declare that relationship between Zoo and Animal in your data model, and any new entities you add which extend Animal will have the same relationship with Zoo — there is no extra work to be done to ensure this.
See the Managed Object Models section of Apple's Core Data Programming Guide for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With