-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
No Entity Manager defined exception #9535
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
Conversation
@@ -62,8 +63,16 @@ public function validate($entity, Constraint $constraint) | |||
|
|||
if ($constraint->em) { | |||
$em = $this->registry->getManager($constraint->em); | |||
|
|||
if(!$em) { | |||
throw new RuntimeException(sprintf("There is not entity manager '%s'", $constraint->em)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use a ConstraintDefinitionException
here instead, as it is an issue in your constraint mapping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and I would say object manager
instead of entity manager
, as the constraint is not specific to the ORM but also works for the ODM projects
Use object manager instead of entity manager
@stof, you right. Also, the class UniqueEntityValidator take a Symfony\Component\Validator\Constraint on construct. But, two lines later, this class is trying to access to "fields" property which is not defined in the Constraint abstract class but inside the UniqueEntity.. Don't you think that an parameter check can be useful ? |
the typehint is required by the interface. You will see the same in all validators |
@@ -354,4 +354,56 @@ public function testAssociatedCompositeEntity() | |||
); | |||
$violationsList = $validator->validate($associated); | |||
} | |||
|
|||
/** | |||
* @group EM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be removed on the 2 tests
@stof thanks for the explanation. With the latest two commits, this PR seems to be ok to be merged. |
} else { | ||
$em = $this->registry->getManagerForClass(get_class($entity)); | ||
|
||
if (!$em) { | ||
throw new ConstraintDefinitionException(sprintf("There is not object manager associated with this entity '%s'", get_class($entity))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unable to find the object manager associated with an entity of class "%s".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabpot done
This PR is linked to this issue : #9534