一般ORM模型在一对多关系上存在矛盾

时间:2022-03-10 18:54:26

I have got a very big problem with the mapping of an OOM to a ROM. Please take a look at the following rules:

将OOM映射到ROM时遇到了很大的问题。请看一下以下规则:

  • we have got two classes/entities: category and item
  • 我们有两个类/实体:类别和项目

  • an item is associated with only one category; that means an item can not reference by more than one category
  • 一个项目只与一个类别相关联;这意味着一个项目不能被多个类别引用

  • a category can references more items
  • 类别可以引用更多项目

That is a simple one to many relation.

这是一个简单的一对多关系。

The ROM looks like the following:

ROM如下所示:

category (cId, ...)
item     (iId, ..., cId) cId reference cId from category

The OOM it is the other way around and looks like (Pseudo-Code):

OOM是另一种方式,看起来像(伪代码):

class category
    // the category instance holds all items
    Item[] items;

(In OOM we can not be sure that an specific item is contained by only one category.)

(在OOM中,我们无法确定特定项目仅包含一个类别。)

Now my question: How can I map this contradiction?

现在我的问题是:我如何映射这个矛盾?

Thanks so much!

非常感谢!

1 个解决方案

#1


0  

I ask this question a little bit to quick.

我问这个问题有点快。

The problem I represent here is one of the generals a OR mapper have to solve. Every OR mapper should handle this problem so the programmer does not worry about.

我在这里代表的问题是OR映射器必须解决的一般问题。每个OR映射器都应该处理这个问题,所以程序员不必担心。

#1


0  

I ask this question a little bit to quick.

我问这个问题有点快。

The problem I represent here is one of the generals a OR mapper have to solve. Every OR mapper should handle this problem so the programmer does not worry about.

我在这里代表的问题是OR映射器必须解决的一般问题。每个OR映射器都应该处理这个问题,所以程序员不必担心。