8000 [DoctrineBridge] support __toString as documented for UniqueEntityVal… · symfony/symfony@ebbe9cf · GitHub
[go: up one dir, main page]

Skip to content

Commit ebbe9cf

Browse files
committed
[DoctrineBridge] support __toString as documented for UniqueEntityValidator
1 parent 817e7cd commit ebbe9cf

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ public function testAssociatedEntity()
482482

483483
$this->buildViolation('myMessage')
484484
->atPath('property.path.single')
485-
->setParameter('{{ value }}', 'object("Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity") identified by (id => 1)')
485+
->setParameter('{{ value }}', 'foo')
486486
->setInvalidValue($entity1)
487487
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
488488
->setCause(array($associated, $associated2))

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ private function formatWithIdentifiers(ObjectManager $em, ClassMetadata $class,
186186
return $this->formatValue($value, self::PRETTY_DATE);
187187
}
188188

189+
if (method_exists($value, '__toString')) {
190+
return (string) $value;
191+
}
192+
189193
if ($class->getName() !== $idClass = \get_class($value)) {
190194
// non unique value might be a composite PK that consists of other entity objects
191195
if ($em->getMetadataFactory()->hasMetadataFor($idClass)) {

0 commit comments

Comments
 (0)
0