核心数据:我可以添加与父实体的关系吗?

发布于 2024-11-03 10:47:20 字数 387 浏览 4 评论 0原文

我创建了 Photo 实体,它有一个 Data 属性来存储图像数据。 PhotoThumbnail 实体的父级。我还在 PhotoThumbnail 之间添加了一对一的关系,以便 Photo 可以拥有 Thumbnail

这似乎有效,但有点令人困惑。

您认为创建另一个具有图像数据属性的名为 Image 的实体并制作 Photo & 是更好的设计吗? ImageThumbnail 子级?

I made the Photo entity, which has a Data attribute to store the image data. Photo is the parent of the Thumbnail entity. I also added a one-to-one relationship between Photo and Thumbnail so that a Photo can have a Thumbnail.

This seems to work but is sort of confusing.

Do you think it's better design to make another entity called Image that has the image data attribute and make Photo & Thumbnail children of Image?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟沫凡尘 2024-11-10 10:47:20

你认为这样设计更好吗?
创建另一个名为 Image 的实体
具有图像数据属性并使
照片& Image 的缩略图子级?

您不应该将实体继承视为进行整洁设计的一种手段,而应该使用它来使多个实体可以处于相同的关系中。

假设您有一个包含图像数据的 Person 实体,但图像的大小或类型不同,但您需要所有图像实体处于相同的关系中。您可以像这样进行设置:

Person{
    images<-->>Image.person
}

Image{
    person<<-->Person.images
}

GIF:Image{
    //... GIF related attributes
}

JPG:Image{
    //... JPG related attributes
}

因为 GIFJPG 实体继承自 Image,因此您可以将它们都放在 Person.images 中关系。

在您的情况下,除了类比之外,似乎没有什么特殊原因可以使 PhotoThumbnail 继承自一个公共的超级实体。

此外,如果您使用 SQLite 存储,则父实体的所有子实体最终都位于同一个表中。对于非常大的数据集,这可能会产生性能问题。因此,这是不为了简洁而使用实体继承的另一个原因。

Do you think it's better design to
make another entity called Image that
has the image data attribute and make
Photo & Thumbnail children of Image?

You shouldn't look at entity inheritance as a means of making a tidy design but instead it should be used such that multiple entities can inhabit the same relationship.

Suppose you had a Person entity that had image data but the images where of different sizes or types but you needed all the image entities to be in the same relationship. You would set things up like so:

Person{
    images<-->>Image.person
}

Image{
    person<<-->Person.images
}

GIF:Image{
    //... GIF related attributes
}

JPG:Image{
    //... JPG related attributes
}

Because the GIF and JPG entities inherit from Image you can put both in the Person.images relationship.

In your case, there appears to be no particular reason, other than analogy to Classes, to make the Photo and Thumbnail inherit from a common super entity.

Also, if you are using an SQLite store, all the subentities of a parent entity end up in the same table. For very large data sets, this can create performance problems. So, that is another reason not to use entity inheritance just for neatness.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文