From 14d13b3036f958fdfb86c95bf2e99bdf189a4983 Mon Sep 17 00:00:00 2001 From: Sam Partington Date: Wed, 30 Jan 2013 11:20:36 +0000 Subject: [PATCH] Now correctly handles UniqueDocument criteria which are references to other Documents. Without this, you'll see the Mongo error 'zero-length keys are not allowed, did you use $ with double quotes?' as it doesn't know how to handle the document. --- Validator/Constraint/UniqueDocumentValidator.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Validator/Constraint/UniqueDocumentValidator.php b/Validator/Constraint/UniqueDocumentValidator.php index 9b77a3e..4aca6c0 100644 --- a/Validator/Constraint/UniqueDocumentValidator.php +++ b/Validator/Constraint/UniqueDocumentValidator.php @@ -116,6 +116,9 @@ private function createCriteria(Document $document, array $fields, array $caseIn $criteria = array(); foreach ($fields as $field) { $value = $document->get($field); + if ($value instanceof Document) { + $value = $value->getId(); + } if (in_array($field, $caseInsensitive)) { $value = new \MongoRegex(sprintf('/^%s$/i', $value)); }