From 78e2449a8d0f901bc54589563b8ae52f5a98ce06 Mon Sep 17 00:00:00 2001 From: eltharin Date: Mon, 24 Mar 2025 11:31:16 +0100 Subject: [PATCH 1/4] add mapped route parameters and aliases corrections Auto stash before rebase of "7.2" z --- doctrine.rst | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/doctrine.rst b/doctrine.rst index 171f8a3348a..39e751a4cac 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -861,6 +861,41 @@ control behavior: The ``message`` option was introduced in Symfony 7.1. +Mapped Route Parameters +~~~~~~~~~~~~~~~~~~~~~~~ + +When many route parameters are used to find more than one entity, +it is mandatory to use ``#[MapEntity]`` attributes and this can become cumbersome:: + + #[Route('/document/{slug}/{id}-{name}/')] + public function showDocument( + #[MapEntity(mapping: ['slug' => 'slug'])] + Category $category, + #[MapEntity(mapping: ['id' => 'id', 'name' => 'name'])] + Document $document, + ): Response + { + // the database queries in this case would be: + // $document = $documentRepository->findOneBy(['id' => 'the id', 'name' => 'the name']); + // $category = $categoryRepository->findOneBy(['slug' => 'the slug']); + } + +As an alternative, you can also use Mapped Route Parameters. + +When adding route parameters, you can now define the mapping between the route parameter and the controller argument:: + + #[Route('/document/{slug:category}/{id:document}-{name:document}/')] + public function showDocument(Document $document, Category $category): Response + { + // the database queries in this case would be: + // $document = $documentRepository->findOneBy(['id' => 'the id', 'name' => 'the name']); + // $category = $categoryRepository->findOneBy(['slug' => 'the slug']); + } + +.. versionadded:: 7.1 + + The ``Mapped Route Parameters`` was introduced in Symfony 7.1. + Updating an Object ------------------ From 58bc7fcfe174073bdc94147dc821235b79b01f24 Mon Sep 17 00:00:00 2001 From: eltharin Date: Tue, 25 Mar 2025 06:52:35 +0100 Subject: [PATCH 2/4] remove traillingslash and backticks --- doctrine.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doctrine.rst b/doctrine.rst index 39e751a4cac..2fa617913f1 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -867,7 +867,7 @@ Mapped Route Parameters When many route parameters are used to find more than one entity, it is mandatory to use ``#[MapEntity]`` attributes and this can become cumbersome:: - #[Route('/document/{slug}/{id}-{name}/')] + #[Route('/document/{slug}/{id}-{name}')] public function showDocument( #[MapEntity(mapping: ['slug' => 'slug'])] Category $category, @@ -884,7 +884,7 @@ As an alternative, you can also use Mapped Route Parameters. When adding route parameters, you can now define the mapping between the route parameter and the controller argument:: - #[Route('/document/{slug:category}/{id:document}-{name:document}/')] + #[Route('/document/{slug:category}/{id:document}-{name:document}')] public function showDocument(Document $document, Category $category): Response { // the database queries in this case would be: @@ -894,7 +894,7 @@ When adding route parameters, you can now define the mapping between the route p .. versionadded:: 7.1 - The ``Mapped Route Parameters`` was introduced in Symfony 7.1. + The Mapped Route Parameters was introduced in Symfony 7.1. Updating an Object ------------------ From aabefe2bfe8dafdbc995bdb16eb57e99c2a67e78 Mon Sep 17 00:00:00 2001 From: eltharin Date: Tue, 25 Mar 2025 07:55:17 +0100 Subject: [PATCH 3/4] Update doctrine.rst Co-authored-by: Oskar Stark --- doctrine.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctrine.rst b/doctrine.rst index 2fa617913f1..dcf4f7bafff 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -894,7 +894,7 @@ When adding route parameters, you can now define the mapping between the route p .. versionadded:: 7.1 - The Mapped Route Parameters was introduced in Symfony 7.1. + The mapped route parameters were introduced in Symfony 7.1. Updating an Object ------------------ From 660235908f5c21f3cd80177bcf564726e0fbe1ed Mon Sep 17 00:00:00 2001 From: eltharin Date: Tue, 25 Mar 2025 11:02:20 +0100 Subject: [PATCH 4/4] from other pr comments --- doctrine.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/doctrine.rst b/doctrine.rst index dcf4f7bafff..e323796a287 100644 --- a/doctrine.rst +++ b/doctrine.rst @@ -875,26 +875,24 @@ it is mandatory to use ``#[MapEntity]`` attributes and this can become cumbersom Document $document, ): Response { - // the database queries in this case would be: + // this would result in the following database queries: // $document = $documentRepository->findOneBy(['id' => 'the id', 'name' => 'the name']); // $category = $categoryRepository->findOneBy(['slug' => 'the slug']); } -As an alternative, you can also use Mapped Route Parameters. - -When adding route parameters, you can now define the mapping between the route parameter and the controller argument:: +By using mapped route parameters, you can define the mapping between the route parameter and the controller argument:: #[Route('/document/{slug:category}/{id:document}-{name:document}')] public function showDocument(Document $document, Category $category): Response { - // the database queries in this case would be: + // this would result in the following database queries: // $document = $documentRepository->findOneBy(['id' => 'the id', 'name' => 'the name']); // $category = $categoryRepository->findOneBy(['slug' => 'the slug']); } .. versionadded:: 7.1 - The mapped route parameters were introduced in Symfony 7.1. + Mapped route parameters were introduced in Symfony 7.1. Updating an Object ------------------