Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoreData Entity Inheritance

Consider that i have two entities with following relationship:

Entity A <-->> Entity B (one-to-many and inverse)

Now consider that i have another entity Entity C that contains all the attributes of Entity B and some others, with following relationship:

Entity A <-->> Entity C (one-to-many and inverse)

Now i can improve the architecture by making Entity B the parent of Entity C.

Entity B
   ^
   |
Entity C

Now, my question is, will the attribute(s) AS WELL AS the relationship(s) be inherited by Entity C? Meaning, do i still need to keep the following relationship (separately)?:

Entity A <-->> Entity C

Also, i couldn't find a good example for entity inheritance in Apple documentation for Core Data. Does anyone know of an online resource that explains this, with example (preferably)?

like image 649
Mustafa Avatar asked Dec 06 '22 01:12

Mustafa


1 Answers

Yes, attributes and relationships and everything else will be inherited. Be careful though, child entities like that will share the same table in sqlite with the parent entity. So if you have C inheriting from B, then a table will be created in sqlite that has the properties for both B and C which the obvious voids in the table. This is not too much of an issue with a simple inheritance like this but if you decide to get "creative" you can end up with your entire model in one table.

like image 118
Marcus S. Zarra Avatar answered Dec 23 '22 01:12

Marcus S. Zarra