Content-Length: 224431 | pFad | http://github.com/symfony/symfony/issues/60637

BE [Routing] Route parameter aliases breaks automatic entity fetching · Issue #60637 · symfony/symfony · GitHub
Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
philiprabbett opened this issue Jun 2, 2025 · 0 comments
Open

Comments

@philiprabbett
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/symfony/symfony/issues/60637

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy