及时存储某一时刻的模型关系

发布于 2024-10-22 04:20:15 字数 293 浏览 2 评论 0原文

我正在开发一个应用程序,允许人们请求为特定工作生成保修。他们提供诸如使用了什么产品等信息...(他们的一些选择是从系统中已有的项目列表中提供的。然后我们根据这些选择为他们生成保修。

我正在努力解决这个概念批准的保修那一刻的快照,当它依赖于可能随时间变化的相关记录时,

我能想到的最简单的方法不是存储与源表(例如product_id)的关系,而是写入另一种方法是不允许从产品表中删除/修改产品,除非没有附加任何保证。指向同一产品的编辑版本?我以前在购物车中这样做过,而且效果很好,我只是有很多关系需要管理,我想知道是否有一种我没有想到的方法?

I'm developing an application that allows people to request a warranty be generated for a particular job. They supply information such as what product was used etc... (some of their choices are provided from a list of items already in the system. We then generate them a warranty based upon those choices.

I'm struggling with the concept of making an approved warranty a snapshot of that moment in time when it depends on related records that may change over time.

The easiest way I can think of doing this is not to store the relationships to the source tables (e.g. product_id) but to rather write the product out as a string. This seems a bit messy. The other way to go is to not allow for the deletion/modification of a product from the products table unless there are no warranties attached to it. Perhaps implementing a 'replaced_with' column that points to an edited version of the same product? I've done this in a shopping cart before, and it's worked pretty well. I just have a lot of relationships to manage and am wondering if there's a way I haven't thought of?

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

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

发布评论

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

评论(1

枉心 2024-10-29 04:20:15

怎么样:

  1. 添加一个“产品停产”表,该表与保修是 1:0。只有列是保修 ID。
  2. 添加“历史产品表”,其中包含:

    与产品表相同的列

    填充日期/时间的附加时间戳字段。

    产品 ID/时间戳的主键

    产品 ID 上的索引

  3. 删除/修改触发器/过程:

    选择产品的所有保修。

    如果有任何保证,则将产品详细信息复制到“历史产品表”,添加主键的第二部分。

    对于找到的每个保修,将一条记录插入“产品停产”表中。

这样做的前提是,您可能希望以不同于现行产品的方式处理停产产品的保修。

What about:

  1. Adding in a "product discontinued" table that is 1:0 with warranty. Only columns are warranty id.
  2. Adding in a "historic product table" that has:

    The same columns as the product table

    An additional timestamp field for the date/time it was populated.

    A primary key of product id/timestamp

    An index on product id

  3. a deletion/modification trigger/procedure that:

    Selects all warranties on the product.

    If there are any warranties, then copy the product details to the "historic product table", adding the second part of the primary key.

    For each warranty found insert a record into the "product discontinued" table.

This is premised on the basis that you will probably want to deal with warranties for discontinued items differently from those for active products.

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