With Symfony2, I need to save an entity before use $form->bind() to compare the old and new one before flush.
I tried some functions :
$command = $repository->findCommandProductsByCommand( $id );
$old_command = clone $command;
// OR $old_command = $command;
$form = $this->createForm(new EditCommandType(), $command);
if( $request->getMethod() == 'POST' )
{
$form->bind($request);
if ( $form->isValid() )
{
And I tried to save a little part of the entity like this :
$old_command = $command->getCommandProducts();
But when i try to access to the data of $old_command with one of these methods, i only get access to the newer value of the object from the form and not the older one.
$form->bind($request) is the main problem, but i didn't find a documentation which describes what exacly does bind().
Best regards
Solution for my case (thanks to zizoujab)
$command_entries = new ArrayCollection();
foreach ($command->getCommandproducts() as $entry) {
$command_entries[] = clone $entry;
}
Now my ArrayCollection $command_entries isn't link to the previous entity.