Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a687f83

Browse files
committed
[DoctrineBridge] Make EntityValueResolver return null if a composite ID value is null
1 parent 85ec307 commit a687f83

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines 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

Lines 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)