如何将 OO 继承映射到关系数据库方案?

发布于 2024-08-07 06:18:41 字数 94 浏览 7 评论 0 原文

我有一个规范的数据模型。有些字段与产品的定价相关。它继承了产品表的某些属性。我想在 MySQL 关系数据库中对这种继承进行建模。我们如何在关系数据库方案中建模面向对象的继承?

I have a canonical data model. Some fields are related to the pricing of a product. It inherits certain attributes from the product table. I want to model this inheritance in a MySQL relational database. How can we model object-oriented inheritance in a relational database scheme?

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

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

发布评论

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

评论(4

野生奥特曼 2024-08-14 06:18:41

Martin Fowler 在他的《企业应用程序架构模式》一书中对此进行了广泛的讨论。获取这本书并研究:

  1. 单表继承

块引用

  1. 类表继承

在此输入图像描述

  1. 具体表继承

块引用

该网站应该会给您一些想法。您可能还想阅读有关继承映射器的部分。每种不同的方法都有其优点和缺点,因此请明智地选择。

Martin Fowler discusses this extensively in his book Patterns of Enterprise Application Architecture book. Get this book and look into:

  1. Single Table Inheritance

Blockquote

  1. Class Table Inheritance

enter image description here

  1. Concrete Table Inheritance

Blockquote

The Website should give you some idea. You might also want to read the section on inheritance mappers. Each of the different approaches have their pros and cons so choose wisely.

狼性发作 2024-08-14 06:18:41

如果您只是想看一些网络文章而不是阅读书籍,您可以通过 Google 搜索找到一些不错的文章:

Generalization Specialization Relational Modeling

gen-spec 模式涵盖了与 OOP 环境中继承所做的许多相同的内容。

如果你用谷歌搜索,

Generalization Specialization Object Modeling

你会得到一批全新的文章,其中大多数都明确提到了继承。

以下标签总结了一种设计技术 。如果您允许奇怪地使用“扩展”一词,这允许您使用子类表来“扩展”类表。虽然涉及一些工作,但这是值得的。

If you just want to look at some web articles instead of reading a book, you can find some good articles by Googling on:

Generalization Specialization Relational Modeling

The gen-spec pattern covers a lot of the same ground that inheritance does in OOP environments.

If you google on

Generalization Specialization Object Modeling

you'll get a whole new batch of articles, most of which mention inheritance explicitly.

There is a design technique that's summarized in the following tag under the info tag. This allows you to use subclass tables to "extend" a class table, if you'll allow a strange use of the word "extend". There's some work involved, but it's worth it.

眸中客 2024-08-14 06:18:41

关系数据库不处理对象(因此也不处理继承)——它们处理关系。您真正要问的是如何将对象结构映射到数据库 - 答案是“这取决于您的 ORM 层”。

查看将对象映射到关系数据库:O/R 映射详细信息一文一些细节。如果您告诉我们您正在使用什么软件堆栈,您可能会得到更中肯的答案。

Relational databases don't deal with objects (and, thus, inheritance) - they deal with relationships. What you're really asking is how to map your object structure to your database - and the answer to that is "it depends on your ORM layer".

Take a look at Mapping Objects to Relational Databases: O/R Mapping In Detail article for some details. If you tell us what software stack you're using, you'll likely get a more to-the-point answer.

风向决定发型 2024-08-14 06:18:41

“数据库管理中的实际问题”的第 6 章可能对您来说很有趣。

可能与所有其他章节一样,但这些与您的问题没有直接关系。

Chapter 6 of "Practical Issues in Database Management" is probably an interesting read for you.

As are all the other chapters, probably, but those don't relate directly to your question.

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