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

Skip to content

[DoctrineBridge] Use $entityClass intead of the the entity class in UniqueEntity #39983

Closed
@YaFou

Description

@YaFou

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

$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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions