Skip to content

Commit

Permalink
Change the array access used in UniqueEntityValidator
Browse files Browse the repository at this point in the history
convert iterator to array if it isnt already (mongodb)

More specific if

Dont do iterator_to_array if object implements \ArrayAccess

CS fix
  • Loading branch information
henrikbjorn committed Feb 6, 2012
1 parent 1bef14a commit 928e352
Showing 1 changed file with 7 additions and 1 deletion.
Expand Up @@ -94,11 +94,17 @@ public function isValid($entity, Constraint $constraint)
$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;
}

Expand Down

0 comments on commit 928e352

Please sign in to comment.