After successfully deserializing the json string in Entity Entity with associations. When perseverance, the Doctrine defines these associations as "new entities" always. How can I update associations only with an identifier and not change the values of related entities if there are any changes?
My case:
I have several database tables with static data. The easiest to store units. (I have a doctrine object called Unit). The table looks like this:
|id|name |ratio | |1 |mgr |1 | |2 |gr |1000 | |3 |Kgr |1000000|
The user can then create an element that also has a server-side doctrine object called Unit. I use the client-side backbone.js model, and when it is updated, it is sent to my Symfony2 application as follows:
Now I deserialize with the JMSSerializer, everything is fine, but I want the doctrine to update only the module identifier of this relationship, and not the entire block.
When I persist, the doctrine complains and tells me that it has found a “new unit” (which is not what I want), and tells me to cascade persist in Entity Entity. But if I do this and someone modifies unit json, won't that change my static Units table?
For example: A bad user modifies Json by sending this:
Of course, I do not want this to happen. I just want to add Unit with id: 1 to the element.
This case is simple, and I could just extract the device by identifier and then set it in essence, but in my real application the Item object is much larger, so I want to process it automatically.
¿Any ideas?
source share