- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 9.7k
Description
Symfony version(s) affected
6.3.0
Description
When a route parameter name matches a relation name in a Doctrine entity, EntityValueResovler is confused without providing the id parameter, such as #[MapEntity(id: 'parameterName')]. While providing the ID works, I think the default behaviour, injecting the first found entity, is incorrect.
Because this "inject first child" behaviour is inconsistent (sometimes the injected value is null, sometimes it's a first entity i n a set), I think this is at least a bug.
How to reproduce
I wrote a minimal reproducer with a few scenarios. Check out https://github.com/janklan/map-entity-bug and follow readme to see it.
You should see something along the lines of:
 
When you click either one of the scenarios (say 2.1), you'll see a dd() result of whatever the DefaultController received:
 
 
The description next to each scenario should tell you whether I expected the $child to be populated or not, and which one.
Possible Solution
When the resolver has no data to fetch stuff, it should resolve into null.
Additional Context
This issue was previously discussed in #47166 and attempts to fix it were done in #47242, but I tripped over it again today, when I found an unexpected populated entity.
Some time ago I also reported the same behaviour in SensioFrameworkBundle repo for the now-deprecated ParamConverter, where I believe it was classed as "won't fix" because of the pending deprecation. I can't see the issues anymore, so I can't give you more detail.