核心数据引用
我的应用程序是基于 CoreData 的,但它们可能是所有关系数据库的共同理论:
我的模型中有一个输出-输入对多关系。每个实体在此关系下可能存在无限数量的链接。识别特定输入或输出的最佳方法是什么?
到目前为止,我实现此目的的唯一方法是在可以保存输出和输入名称的关系中放置一个中间实体。然后,实体可以循环遍历其输入/输出,以在需要时找到正确的关系。有更好的办法吗?
实际上,我试图提供一个通用实体,它可以与其他通用实体有任意数量的关系。
如果我的描述不是最清楚,请道歉。
编辑回应以下答案: 首先感谢您的回复。我心里当然有一种双向太多的关系。但是,如果一个小部件有两个其他小部件链接到其输入关系,那么确定提供哪个输入的最佳方法是什么,例如“年龄”或“年服务”,当两者都可能具有此属性但我只对特定的感兴趣时每个的价值?
My application is CoreData based but they may be a common theory for all relational databases:
I have a Output-Input to-many relationship in my model. There are potentially an unlimited number of links under this relationship for each entity. What is the best way to identify a specific input or output?
The only way I have achieved this so far is to place an intermediate entity in the relationship that can hold an output and input name. Then an entity can cycle through its inputs/outputs to find the right relationship when required. Is there a better way?
Effectively I am trying to provide a generic entity that can have any number of relationships with other generic entity.
Apologies if my description isn't the clearest.
Edit in response to the answer below:
Firstly thank you for your response. I certainly have a two-way too-many relationship in mind. But if a widget has 2 other widgets linked to its Inputs relationship what is the best way of determining which input is supplying, say, 'Age' or 'Years Service' when both may have this property but I'm only interested in a specific value from each?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我和约书亚一样困惑 - 它告诉我,你可能还没有清楚地了解你想要实现的目标,或者它有点复杂(两者兼而有之?)。
我最好的猜测是你有类似的东西:
Entity Widget
属性:
关系
(其中根据标准,a ->> 是一对多关系,<<->> 是具有一对多反向关系的对多关系)。
因此,每个小部件将存储它作为输出的小部件集和作为输入的小部件集。
因此,特定的小部件维护一组输入小部件和输出小部件。这些关系中的每一个也是相反的,因此您可以 - 对于输入或输出中的任何小部件 - 看到您的小部件位于其输入或输出列表中。
但这实在太丑陋了。
我认为你的问题是如何在标记关系的同时实现上述目标。您提到您希望每个关系都有一个字符串标识符(唯一的?)。
您可以通过以下方式执行此操作:
在其中为每个双边关系创建一个新的 widgetNamedRelationship。请注意,我假设每个关系都是双面的。
然后,对于每个小部件,您都有一组命名输入和命名输出。这也允许小部件附加到自身,但只有单独的输入和输出总线。
因此,对于名为 aWidget 的 Widget 实例的实现类中的示例“age”,您将具有以下内容:
NSPredicate *agePredicate = [NSPredicate predicateWithFormat:@"name='age'"];
NSSet *ageInputs = [aWidget.inputs FilteredSetUsingPredicate:agePredicate];
我明白这个问题了吗?
I'm as confused as Joshua - which tells me that it may be that you haven't got a clear picture of what you're trying to achieve or that it is somewhat complex (both?).
My best guess is that you have something like:
Entity Widget
Attributes:
Relationships
(where as per standard a ->> is a to-many relationship and <<->> is a to-many relationship with a to-many reverse relationship).
So each widget will be storing the set of widgets that it has as outputs and the set of widgets it has as inputs.
Thus a specific widget maintains a set of inputWidgets and outputWidgets. Each of these relationships is also reversed so you can - for any of the widgets in the input or output - see that your widget is in their list of inputs or outputs.
This is bloody ugly though.
I think your question is how to achieve the above while labelling a relationship. You mention you want to have a string identifier (unique?) for each relationship.
You could do this via:
Where you create a new widgetNamedRelationship for each double sided relationship. Note that I'm assuming that every relationship is double sided.
Then for each widget you have a set of named inputs and named outputs. This also allows for widgets to be attached to themselves but only of there are separate input and output busses.
So then for your example "age" in your implementation class for Widget instance called aWidget you'd have something like:
NSPredicate *agePredicate = [NSPredicate predicateWithFormat:@"name='age'"];
NSSet *ageInputs = [aWidget.inputs filteredSetUsingPredicate:agePredicate];
Have I understood the question?
如果您希望能够充分利用快速高效的店内查询的便利性,确实没有更好的方法了。目前尚不清楚您在附加评论中要问什么,我想这就是您尚未得到任何答案的原因。
请记住,核心数据支持多对多关系,无需“连接表”。
如果 Widget 有许多输入或输出(我怀疑它们可能是同一个实体),那么 Widget 和输入之间的多对多、双向关系(用核心数据的说法是一种逆关系)就足够了。然后您需要做的就是查看您的Input 实例是否在Widget 实例的-inputs 中,或者Widget 实例是否在Input 实例的-widgets 中。
这就是您要找的吗?如果没有,请尝试澄清您的问题(通过编辑它,而不是通过附加评论:-))。
There really is no better way if you want to be able to take full advantage of the conveniences of fast and efficient in-store querying. It's unclear what you're asking in your additional comments, which I suppose is why you haven't gotten any answers yet.
Keep in mind Core Data supports many-to-many relationships without a "join table."
If Widget has many Inputs or Outputs (which I suspect could be the same entity), then a many-to-many, two-way relationship (a relationship with an inverse, in Core Data parlance) between Widget and Input is all you need. Then all you need to do is see if your Input instance is in the Widget instance's -inputs or if a Widget instance is in the Input instance's -widgets.
Is that what you were looking for? If not, please try to clarify your question (by editing it, not by appending comments :-)).