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 ma开发者_JAVA技巧king 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?
What about:
- Adding in a "product discontinued" table that is 1:0 with warranty. Only columns are warranty id.
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
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.
精彩评论