Closed
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 protected]
.
$dto = new Dto();
$dto->email = '[email protected]';
$constraints = $validator->validate($dto);
// One violation expected
Possible Solution
Change this line to:
$em = $this->registry->getManagerForClass($constraint->entityClass ?? \get_class($entity));
Additional context
Is it intentional?