Skip to content

Commit c21c3bb

Browse files
committed
merged branch jmikola/patch-2 (PR symfony#3535)
Commits ------- a5ed6ab [DoctrineBridge] Rewind MongoCursor before use in unique validator Discussion ---------- [DoctrineBridge] Rewind MongoCursor before use in unique validator Fixes a regression I introduced in: 265360d --------------------------------------------------------------------------- by jmikola at 2012-03-08T22:11:32Z This was also reported in doctrine/DoctrineMongoDBBundle#84. Let it be stated that we should create some functional tests for this validator :)
2 parents 58bd10d + a5ed6ab commit c21c3bb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ public function isValid($entity, Constraint $constraint)
9494
$repository = $em->getRepository($className);
9595
$result = $repository->findBy($criteria);
9696

97+
/* If the result is a MongoCursor, it must be advanced to the first
98+
* element. Rewinding should have no ill effect if $result is another
99+
* iterator implementation.
100+
*/
101+
if ($result instanceof \Iterator) {
102+
$result->rewind();
103+
}
104+
97105
/* If no entity matched the query criteria or a single entity matched,
98106
* which is the same as the entity being validated, the criteria is
99107
* unique.

0 commit comments

Comments
 (0)