Core Data entity inheritance --> limitations?

前端 未结 3 1516
一向
一向 2021-01-05 10:30

I thought I\'ll post this to the community. I am using coredata, and have two entities. Both entities have a hierarchical relationship. I am noticing quite a lot of duplic

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-05 10:50

    I thought it would be useful to mention that the Notes app on iOS 10 uses inheritance in its Core Data model. They use a base entity SyncingObject, that has 7 sub-entities including Note and Folder. And as you mentioned all of these are stored in the same SQLite table which has a whopping 106 columns, and since are shared among all entities most are NULL. They also implemented the folder-notes one-to-many relation as a many-to-many which creates a pivot table, which might be a work-around for an inheritance problem.

    There are a couple of advantages to using entity inheritance that likely outweigh these storage limitations. For example, a unique constraint can be unique across entities. And a fetch request can return different entities making UI that uses fetched results controller simpler, e.g. grouping by accounts or folders in a sidebar.

提交回复
热议问题