开发者

Parent Entity and Relationship in Core Data

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜