Skip to content

Commit 261a459

Browse files
committed
bug #9647 use the correct class name to retrieve mapped class' metadata and reposi... (xabbuh)
This PR was merged into the 2.2 branch. Discussion ---------- use the correct class name to retrieve mapped class' metadata and reposi... ...tory | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #9646 | License | MIT | Doc PR | The validation context isn't necessarily the entity being validated. In case that you added the Unique Entity constraint inside your custom type via the ``constraints`` option the validation context will be the ``Form`` class itself. Thus, not the validation context should be used to get the class metadata and the repository of the validated entity, but the entity itself should be used. Commits ------- cd4df11 use the correct class name to retrieve mapped class' metadata and repository
2 parents 3b70329 + cd4df11 commit 261a459

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ public function validate($entity, Constraint $constraint)
7474
}
7575
}
7676

77-
$className = $this->context->getClassName();
78-
$class = $em->getClassMetadata($className);
77+
$class = $em->getClassMetadata(get_class($entity));
7978
/* @var $class \Doctrine\Common\Persistence\Mapping\ClassMetadata */
8079

8180
$criteria = array();
@@ -110,7 +109,7 @@ public function validate($entity, Constraint $constraint)
110109
}
111110
}
112111

113-
$repository = $em->getRepository($className);
112+
$repository = $em->getRepository(get_class($entity));
114113
$result = $repository->{$constraint->repositoryMethod}($criteria);
115114

116115
/* If the result is a MongoCursor, it must be advanced to the first

0 commit comments

Comments
 (0)