这是常见的数据库设计/面向对象映射技术吗?

发布于 2024-09-09 06:09:47 字数 944 浏览 4 评论 0原文

最近,我被要求重写一个预订系统,该系统的性能未达到客户的预期。我发现数据库模式/对象映射技术曾经非常不寻常,并且想知道是否有其他人遇到过类似的事情。

旧系统使用大约 25 个类来处理客户、约会和订单等内容,每个类都有一个名为“class_id”的唯一属性。

查看数据库时,每个类都有一个相应的表,但是它们都不包含任何外键字段,尽管它们必须以某种方式链接,因为应用程序允许客户端执行各种级别的报告。

经过进一步调查,我注意到数据库包含另一个名为“application_hierarchy”的表。

该表包含 4 列,映射了不同记录之间的关系:

  1. class_id - 标识记录类型
  2. object_id - 引用其相应表中记录的 id
  3. Parent_class_id - 标识相关记录的记录类型
  4. Parent_object_id - 引用其相应表中父记录的 id

例如,如果客户 5 有 3 个不同的订单,ID 号分别为 10、11 和 12:

客户类别为 ID 4 订单类别为 ID 7 因此:

class_id | object_id | parent_class_id | parent_object_id
7          10          4                 5
7          11          4                 5 
7          12          4                 5

对于应用程序中的每个对象记录,此表中都会有大量行,这些行将与大型连接查询结合起来以创建报告。

尝试将这些数据导入到新模式中绝对是一场噩梦,主要是因为原作者忽略了记录哪个类由哪个 id 号标识!

这是一种常用的技术还是原始开发人员只是 PITA?

任何建议/意见表示赞赏。

谢谢。

I've recently been asked to rewrite a booking system that was not performing as well as a client would like. I've found the database schema / object mapping technique used to be quite unusual and was wondering if anyone else has come across anything similar.

The old system used about 25 classes for things like customers, appointments and orders etc, each of which has a unique property called 'class_id'.

When looking at the database, each class had a corresponding table, however none of them contained any foreign key fields although they had to be linked in some way as the application allowed the client to carry out various levels of reporting.

After further investigation, I noticed that the database contained another table called 'application_hierarchy'.

This table contained 4 columns which mapped out the relations between different records:

  1. class_id - Which identified the record type
  2. object_id - Which referenced the id of the record within its corresponding table
  3. parent_class_id - Which identified the record type of the related record
  4. parent_object_id - Which referenced the id of the parent record within its corresponding table

For example, if customer 5 has three different orders with id numbers 10, 11 and 12:

The Customer class was ID 4
The Order class was ID 7
So:

class_id | object_id | parent_class_id | parent_object_id
7          10          4                 5
7          11          4                 5 
7          12          4                 5

There would be a large number of rows in this table for every single object record in the application and these would be combined with a large join query to create the reports.

Trying to import this data into the new schema has been an absolute nightmare, mainly because the original author has neglected to document which class is identified by which id number!

Is this a commonly used technique or was the original developer just being a PITA?

Any advice / comments appreciated.

Thanks.

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

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

发布评论

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

评论(1

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