I want to design data models of the following:
I have a Document object who has a client and DocumentLines.
Each line contains an Item and its quantity and price (See first row in the attached picture).
In the document I want to display the lines along with the items' part number, description, and date code.
Problem Time
So far, so good. I can use data relations to attach only the ID of the relevant object to relate it.
But! Let's imagine this scenraio
I have item A = { part_number: 'pn1', description: 'my item', date_code: 2015}, which has was instered into DocA.
When I enter DocA, I see the client had bought pn1 with the date code of 2015.
Now, when re-stocking this item, we get a newer date code of the item.
It is no longer 2015, but rather, 2016.
So I update my item: A = { part_number: 'pn1', description: 'my item', date_code: 2016}. Now, when I enter DocA, I see that the client had bought A with the date code of 2016!!
This is wrong!
The details of the order should remain the same, and not be dynamically changed.
And also, what happens if I delete A? What will I see in DocA?
Question
How do I solve my puzzle, with one addition:
I need to allow changing item detail changes in documents.
Meaning, add something ad-hoc for the specific document (not line-comments).
What I came up with (which is the current solution), is duplicating the needed data in the DocumentLine object.
Though that seems so wrong, I can't come up with a better solution.
I'd like to hear your opinion.
