Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

EntityValueResolver injecting entities when it shouldn't #50739

Copy link
Copy link
Closed
@janklan

Description

@janklan
Issue body actions

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:

image

When you click either one of the scenarios (say 2.1), you'll see a dd() result of whatever the DefaultController received:

image image

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.