I am using symfony 1.4 with Doctrine. I have built a form which uses a table that has the Versionable behaviour. As expected, Versionable creates a new version of the row every time the form is submitted and saved. My problem is that I would like to prevent it doing so if the actual values submitted are not any different from the original values put into the form via the edit action.
I know that I can do this with javascript relatively easily. I'm just curious as to whether symfony or Doctrine have this functionality already, and how it is used if so. It just seems like something that symfony would have a method for, which could be checked right before $form->save()
is called. Am I dreaming or perhaps missing something obvious?
You can use the DoctrineRecord::getModified()
function which returns an array of the modified fields and associated values from an overridden save()
function or in a listener (preSave
would be the best I guess).
If the new values are not any different, you can bypass the actual call to save()
, so no new version is created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With