CoreData实体继承

Mus*_*afa 4 iphone inheritance entity core-data

考虑到我有两个具有以下关系的实体:

Entity A <-->> Entity B (one-to-many and inverse)
Run Code Online (Sandbox Code Playgroud)

现在考虑我有另一个实体C,它包含实体B和其他一些的所有属性,具有以下关系:

Entity A <-->> Entity C (one-to-many and inverse)
Run Code Online (Sandbox Code Playgroud)

现在,我可以通过使实体B成为实体C的父代来改进体系结构.

Entity B
   ^
   |
Entity C
Run Code Online (Sandbox Code Playgroud)

现在,我的问题是,属性是否与实体C一起继承关系?意思是,我还需要保持以下关系(单独)吗?:

Entity A <-->> Entity C
Run Code Online (Sandbox Code Playgroud)

另外,我在Core Data的Apple文档中找不到实体继承的好例子.有没有人知道一个解释这个的在线资源,例如(最好)?

Mar*_*rra 13

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.

  • 是的,我很积极.我已经测试了它,并且无数次地看到了它.我是参考:) (5认同)