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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
YaFou opened this issue Jan 26, 2021 · 4 comments
Closed

Comments

@YaFou
Copy link
Contributor

YaFou commented Jan 26, 2021

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?

@xabbuh
Copy link
Member

xabbuh commented Jan 27, 2021

I think #38662 would help you, right?

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Could I get a reply or should I close this?

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants