Skip to content

Commit

Permalink
[DoctrineBridge] Rewind MongoCursor before use in unique validator
Browse files Browse the repository at this point in the history
Fixes a regression I introduced in: 265360d
  • Loading branch information
jmikola committed Mar 8, 2012
1 parent 58bd10d commit a5ed6ab
Showing 1 changed file with 8 additions and 0 deletions.
Expand Up @@ -94,6 +94,14 @@ public function isValid($entity, Constraint $constraint)
$repository = $em->getRepository($className);
$result = $repository->findBy($criteria);

/* If the result is a MongoCursor, it must be advanced to the first
* element. Rewinding should have no ill effect if $result is another
* iterator implementation.
*/
if ($result instanceof \Iterator) {
$result->rewind();
}

/* 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.
Expand Down

0 comments on commit a5ed6ab

Please sign in to comment.