This is an excerpt from my POST data:
...
lead[contacts][6][firstName]: test
lead[contacts][6][id]: 543961
lead[contacts][6][lastName]: test
...
lead[contacts][7][firstName]: John
lead[contacts][7][id]: 296310
lead[contacts][7][lastName]: Doe
...
lead[contacts][8][firstName]: foo
lead[contacts][8][id]: 296320
lead[contacts][8][lastName]: bar
...
lead[contacts][9][firstName]: foo
lead[contacts][9][id]: 296330
lead[contacts][9][lastName]: bar
...
I see the same post data in Symfony profiler's Request / POST Parameters section. I'm providing the data as text here, because a screenshot would contain lots of other unnecessary information. Due to privacy reasons I replaced the original first and last name values. Yes, "foo bar" appears twice.
My problem is that Symfony mixes up IDs and content after handling the request:
$lead = $this->getRepository()->findWithContacts($id);
$form = $this->createForm(LeadType::class, $lead);
$form->handleRequest($request);
screenshot from Symfony profiler's Form / Submitted Data section:
As you can see, test now has John Doe's ID 296310. I have no idea why this is happening. When persisting the form data later, it causes lots of inserts and deletes. I also observed that data was completely lost after processing the form.