Skip to content

Commit 3416d56

Browse files
committed
[DoctrineBridge] Deprecated using IdReader when optimization is not possible
1 parent 3df05e0 commit 3416d56

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/Symfony/Bridge/Doctrine/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* changed guessing of DECIMAL to set the `input` option of `NumberType` to string
88
* deprecated not passing an `IdReader` to the `DoctrineChoiceLoader` when query can be optimized with a single id field
9+
* deprecated passing an `IdReader` to the `DoctrineChoiceLoader` when entities have a composite id
910

1011
4.2.0
1112
-----

src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public function __construct(ObjectManager $manager, string $class, IdReader $idR
4949
{
5050
$classMetadata = $manager->getClassMetadata($class);
5151

52+
if ($idReader && !$idReader->isSingleId()) {
53+
@trigger_error(sprintf('Passing an instance of "%s" with an entity class "%s" that have a composite id is deprecated since 4.3 and will throw an exception in 5.0.', IdReader::class, $class), E_USER_DEPRECATED);
54+
}
55+
5256
if ((5 > \func_num_args() || false !== func_get_arg(4)) && null === $idReader) {
5357
$idReader = new IdReader($manager, $classMetadata);
5458

src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/DoctrineChoiceLoaderTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,27 @@ public function testLoaderWithoutIdReaderCanBeOptimized()
470470

471471
$this->assertSame([$obj1], $loader->loadChoicesForValues(['1']));
472472
}
473+
474+
/**
475+
* @group legacy
476+
*
477+
* @deprecationMessage Passing an instance of "Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader" with an entity class "stdClass" that have a composite id is deprecated since 4.3 and will throw an exception in 5.0.
478+
*/
479+
public function testPassingIdReaderWithoutSingleIdEntity()
480+
{
481+
$idReader = $this->createMock(IdReader::class);
482+
$idReader->expects($this->once())
483+
->method('isSingleId')
484+
->willReturn(false)
485+
;
486+
487+
$loader = new DoctrineChoiceLoader(
488+
$this->om,
489+
$this->class,
490+
$idReader,
491+
$this->objectLoader
492+
);
493+
494+
$this->assertInstanceOf(DoctrineChoiceLoader::class, $loader);
495+
}
473496
}

0 commit comments

Comments
 (0)