From 928e352d09a6bb0b566e61bc7482ead1d4859442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bj=C3=B8rnskov?= Date: Mon, 6 Feb 2012 08:57:54 +0100 Subject: [PATCH] Change the array access used in UniqueEntityValidator convert iterator to array if it isnt already (mongodb) More specific if Dont do iterator_to_array if object implements \ArrayAccess CS fix --- .../Validator/Constraints/UniqueEntityValidator.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php index 1783a5a250..899afcf5ac 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php +++ b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php @@ -94,11 +94,17 @@ class UniqueEntityValidator extends ConstraintValidator $repository = $em->getRepository($className); $result = $repository->findBy($criteria); + // MongoDB will return a Cursor so we need to change it to an array + // so it is compatible with the orm returning an array + if ($result instanceof \Iterator && !$result instanceof \ArrayAccess) { + $result = iterator_to_array($result); + } + /* If no entity matched the query criteria or a single entity matched, * which is the same as the entity being validated, the criteria is * unique. */ - if (0 === count($result) || (1 === count($result) && $entity === $result[0])) { + if (0 === count($result) || (1 === count($result) && $entity === reset($result))) { return true; }