Good day to all!
Faced the following task: I have a certain Model Model, with a property that changes over time (history). I need to keep these changes in history in order to use it for statistics in the future. To store the entire history in the database, I decided that it would be reasonable to specify the type for the history property - json_array. And store this story in one cell in the database itself.
Accordingly, the question is: Now, every time I change a property, I need to create an object, get the current value of history get the current array, add a new value to it, save the array. This is done with the following code:
$entity = $em->getRepository('AppBundle:Model')->find($id); $history = $entity->getHistory(); $history[date('Ymd H:i:s')] = $currentValue; $entity->setHistory(); $em->persist($entity); $em->flush(); I feel that this is a perversion. Is it possible to somehow solve this problem using Symfony and Doctrine?
Thank you in advance!