0

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:

Symfony submit data

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.

fishbone
  • 3,140
  • 2
  • 37
  • 50

1 Answers1

0

Your returned value in the screenshot is a LeadContact, but it looks like you're trying to get a Lead. Regardless, you should be passing in the class name of whichever repository you're trying to call.

$yourVar = $this->getRepository(YourClass::class)->findMethod($id);

I'm guessing you want Lead and not LeadContact like:

$lead = $this->getRepository(Lead::class)->findWithContacts($id);
Ollie in PGH
  • 2,559
  • 2
  • 16
  • 19
  • My Lead entity has a OneToMany relation to LeadContact. Therefore, my LeadType contains an embedded form collection "contacts" representing its LeadContact entries. – fishbone Mar 21 '18 at 07:14