V
V
Vlad Osadchyi2019-09-17 15:08:44
Yii
Vlad Osadchyi, 2019-09-17 15:08:44

How to properly organize saving the state of the model before changing?

There is a product model that has many possible connections with other models (1-M, MM, M-1, 1-1).
Task: before changing the product fields, you need to save the current values. After the change, it should be possible to view the changes and roll back to the previous one. condition.
So far I have two ideas:
1) To take out in a separate table. only changed fields in json format
2) Completely copy the model into a separate table.
But for me, the main difficulty is related / intermediate tables, since they will also have to be duplicated ...
If you have ideas or materials on how to organize all this, please share, thanks in advance.
The whole thing works on yii2, maybe there are ready-made tools for this that I could not find?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2019-09-17
@VladOsadchyi

Create an additional json field and store the state of the current fields, version or just the date of creation there. When modifying, you add new data to the array. When rolling back, simply replace the current data with the data from the version. But this is such a solution)
Here is more detail. https://m.habr.com/en/post/101544/
If it's simple. My thoughts are like this. In general, it is better to add other tags and maybe something else will be prompted. It's not really about Yii

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question