Skip to content

[Routing] Route parameter aliases breaks automatic entity fetching #60637

Open
@philiprabbett

Description

@philiprabbett

Symfony version(s) affected

7.4.0

Description

I'm currently using "route parameter mapping" within a controller that handles CRUD for an entity that represents a join table in a many-to-many relationship, very similar in setup to the QuestionTag entity described in this symfony cast: https://symfonycasts.com/screencast/doctrine-relations/complex-many-to-many.

As it's currently set up in 7.3.x, I'm able to have a create method automatically get the first entity in the relationship, I'm also able to have other methods such as an update method automatically get the join entity via the two params in the route.

In 7.4.0, this has changed and I'm no longer able to perform a create operation.

How to reproduce

My logic is something like the following

#[Route('/tags/{tag:questionTag}/questions'])]
class QuestionTagController extends AbstractController
    #[Route(methods: [Request::METHOD_POST])]
    public function create(
        #[MapEntity(id: 'questionTag')]
        Tag $tag,
    #[Route('/{question:questionTag}', methods: [Request::METHOD_PATCH])]
    public function update(
        QuestionTag $questionTag

What I've found in parameter bag when attempting the create

- 7.3.x
- questionTag = "my-identifier-here"
- _route_mapping = [
-   tag = "questionTag"
- ]
+ 7.4.0
+ questionTag = [
+   tag = "my-identifier-here"
+ ]
+ _route_mapping = [
+   tag = [
+     0 = "questionTag"
+     1 = "tag"
+   ]
+ ]

Possible Solution

Move the upper most route inside each method route and rename the parameter mapping removing the need for MapEntity in this case.

    #[Route('/tags/{tag}/questions', methods: [Request::METHOD_POST])]
    public function create(
        Tag $tag,
    #[Route('/tags/{tag:questionTag}/questions/{question:questionTag}', methods: [Request::METHOD_PATCH])]
    public function update(
        QuestionTag $questionTag

It does bring #[MapEntity(id: ...)] into question however and therefore this is not a real solution to the problem

Additional Context

No response

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy