Here is my situation. I have the following tables:
- Product
- Product Attribute
- Order Product (references a product_id and an order_id)
- Order Product Attribute (references an order_product and a product_attribute)
When an admin goes in to edit a product attribute (for instance "color"), he may delete that attribute by mistake and later add it back. If orders have already been placed for that product, when he deletes and re-adds the attribute, its ID in the Product Attribute table changes. This make it so that the Order Product Attribute references a non-existent attribute ID (though the attribute does still exist).
What is the best way to go about solving this problem? Maybe I'm just in need of a different perspective on the issue.
[Note: the issue could also occur (just as importantly) if when editing the product, all of the attributes are flushed and the ones currently selected, which may be the same, are re-added.]