-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Closed
Closed
Copy link
Description
Symfony version(s) affected: >= 4.4
Description
I have a DTO which has constraints. One of them is the UniqueEntity constraint. I have specified the class of the entity to retrieve the good manager. However, the validator tries to retrieve the manager from the class of the DTO (which has not manager and repository).
How to reproduce
/**
* @UniqueEntity(fields={"email"}, entityClass="App\Entity\Entity")
*/
class Dto
{
public $email;
}
class Entity
{
private $email;
}
Add a new entry in the database of entity Entity
with email email@symfony.com
.
$dto = new Dto();
$dto->email = 'email@symfony.com';
$constraints = $validator->validate($dto);
// One violation expected
Possible Solution
symfony/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php
Line 71 in 4b8983a
$em = $this->registry->getManagerForClass(\get_class($entity)); |
Change this line to:
$em = $this->registry->getManagerForClass($constraint->entityClass ?? \get_class($entity));
Additional context
Is it intentional?
ro0NLOskarStark