Skip to content

Navigation Menu

Sign in
Appearance settings

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

Commit 5cffe22

Browse filesBrowse files
committed
bug #57625 [DoctrineBridge] Make EntityValueResolver return null if a composite ID value is null (MatTheCat)
This PR was merged into the 6.4 branch. Discussion ---------- [DoctrineBridge] Make `EntityValueResolver` return `null` if a composite ID value is `null` | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | N/A | License | MIT My use-case is the upsert of an entity identified by two values. I have an `update` route with these two values as route parameters, and a `create` route with only one. In that case the second value is `null` but the `EntityValueResolver` will still call the repository’s `find` method, resulting in a `MissingIdentifierField` exception: > The identifier [VALUE] is missing for a query of [ENTITY] This PR makes the `EntityValueResolver` return `null` in this case, like when a scalar ID is `null`. Commits ------- 87f1884 [DoctrineBridge] Make `EntityValueResolver` return `null` if a composite ID value is `null`
2 parents 3804b46 + 87f1884 commit 5cffe22
Copy full SHA for 5cffe22

File tree

2 files changed

+17
-0
lines changed
Filter options

2 files changed

+17
-0
lines changed

‎src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/ArgumentResolver/EntityValueResolver.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ private function find(ObjectManager $manager, Request $request, MapEntity $optio
104104
if (false === $id || null === $id) {
105105
return $id;
106106
}
107+
if (\is_array($id) && \in_array(null, $id, true)) {
108+
return null;
109+
}
107110

108111
if ($options->evictCache && $manager instanceof EntityManagerInterface) {
109112
$cacheProvider = $manager->getCache();

‎src/Symfony/Bridge/Doctrine/Tests/ArgumentResolver/EntityValueResolverTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/ArgumentResolver/EntityValueResolverTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ public function testResolveWithNullId()
144144
$this->assertSame([null], $resolver->resolve($request, $argument));
145145
}
146146

147+
public function testResolveWithArrayIdNullValue()
148+
{
149+
$manager = $this->createMock(ObjectManager::class);
150+
$registry = $this->createRegistry($manager);
151+
$resolver = new EntityValueResolver($registry);
152+
153+
$request = new Request();
154+
$request->attributes->set('nullValue', null);
155+
156+
$argument = $this->createArgument(entity: new MapEntity(id: ['nullValue']), isNullable: true,);
157+
158+
$this->assertSame([null], $resolver->resolve($request, $argument));
159+
}
160+
147161
public function testResolveWithConversionFailedException()
148162
{
149163
$manager = $this->getMockBuilder(ObjectManager::class)->getMock();

0 commit comments

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