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
- bug #38604 [DoctrineBridge] indexBy does not refer to attributes, but to column names (xabbuh) This PR was merged into the 3.4 branch. Discussion ---------- [DoctrineBridge] indexBy does not refer ... — committed to symfony/symfony by fabpot 4 years ago
- bug #38628 [DoctrineBridge] indexBy could reference to association columns (juanmiguelbesada) This PR was squashed before being merged into the 3.4 branch. Discussion ---------- [DoctrineBridge] ... — committed to symfony/symfony by nicolas-grekas 4 years ago
- bug #39667 [DoctrineBridge] Take into account that indexBy="person_id" could be a db column name, for a referenced entity (victormacko) This PR was merged into the 4.4 branch. Discussion ---------- ... — committed to symfony/symfony by xabbuh 3 years ago
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