核心数据:抽象实体和继承关系 [英] Core Data: Abstract entities and inheritance relationships

查看:129
本文介绍了核心数据:抽象实体和继承关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的精确模型很复杂,所以说,我在Xcode的核心数据建模师模拟水果和他们的种子。这里有一些伪核心数据代码:

My exact model is complicated to explain, so say that I'm modeling fruits and their seeds in Xcode's Core Data modeler. Here's some "pseudo Core Data code":

abstractEntity Fruit
attribute sweetness
relationship Seed

abstractEntity Seed
attribute shape

concreteEntity Apple inherits Fruit
concreteEntity Orange inherits Fruit

concreteEntity AppleSeed inherits Seed
concreteEntity OrangeSeed inherits Seed

我以这种方式建模的原因是我想要能够获取混合的水果,并按他们的种子形状排序。给定这个模型,这里是我的问题:

The reason I modeled in this way is that I want to be able to fetch a mix of fruits and sort them by their seed shapes. Given this model, here's my question:

在Xcode建模器(即从GUI)有任何直接的方式,将使我能够指定苹果只能AppleSeeds和Oranges只能有OrangeSeeds?在上面的模型中,具体的水果继承了一个抽象的种子关系,我需要它来获取和排序混合的水果/种子,但我没有看到任何方式来强制每个混凝土水果必须具有的种子关系。

Is there any direct way in the Xcode modeler (i.e., from the GUI) that will enable me to specify that Apples can only have AppleSeeds and Oranges can only have OrangeSeeds? In the model above, concrete fruits inherit an abstract Seed relationship, which I need in order to fetch and sort mixed fruits/seeds, but I don't see any way to enforce the exact Seed relationship that each concrete fruit must have.

我看到许多不同的方法强制在建模GUI之外,但只是想确保我不缺少的东西。任何建议?

I see lots of different ways to enforce this outside of the modeling GUI, but just want to make sure I'm not missing something. Any suggestions?

希望此示例有意义。

推荐答案

只有我能想到的方法是从种子关系中删除种子关系,并将特定的AppleSeed和OrangeSeed关系在子实体中。你可以在子实体中重写关系,而不从超类中删除,但据我所知,模型编辑器没有办法做你正在描述的内容。

The only way I can think of is to remove the seed relationship from the superentity and put specific AppleSeed and OrangeSeed relationships in the subentities. You may be able to override the relationship in the subentities without removing it from the superentity but as far as I know there's no way in the model editor to do what you're describing.

这篇关于核心数据:抽象实体和继承关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆