When I submit my form and I get the team in the database (no INSERT / no UPDATE before), Doctrine returns the new member's ID (I was selected in the form), when I had already the old member's ID in the database.
How to fix the issue?
Thank.
// Get team datas
$teams = $this->getDoctrine()->getRepository(Teams::class)->find($id);
echo $teams->getMember()->getId(); // Display 5 (actual member)
// Create Form
$form = $this->createFormBuilder($teams)
->setAction($this->generateUrl('teams_update'))
->add('member', EntityType::class, array(
'class' => Members::class,
'choice_label' => 'login'
))
->add('name', TextType::class)
->add('status', CheckboxType::class, array('required' => false))
->getForm();
// Submit Form
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
// Get team datas again to compare
$teamsAfter = $this->getDoctrine()->getRepository(Teams::class)->find($id);
echo $teamsAfter->getMember()->getId(); // Display 6 and no 5 (member selected in form, but no save in database)
echo $teams->getMember()->getId(); // Display 6 too (member selected in form, but no save in database)
}