symfony: [DoctrineBridge][DoctrineExtractor] Exception in form validation for field with indexBy

Symfony version(s) affected: 4.4.11

Description
Form validation throws an exception on relation field which contains indexBy definition: No mapping found for field 'foo_id' on class 'App\Entity\Foo'.

How to reproduce

    /**
     * @var Collection|Foo[]
     * @ORM\OneToMany(targetEntity="App\Entity\Foo", mappedBy="bar", indexBy="foo_id", cascade={"persist", "remove"}, orphanRemoval=true)
     * @Assert\Valid()
     */
    private $foos;

Possible Solution
When I change indexBy from “foo_id” to “foo” no exception is thrown. However indexBy will stop working as it suppose to.

Additional context
I have updated project from Symfony v.4.3.4 where it was working.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Here we go https://github.com/juanmiguelbesada/symfony-issue-37982

EDIT: I reproduce it on symfony 5, but it fails on 4.3 and 4.4 as well

I’m on it