public function validateUnique($value, Constraint $constraint)
{
$classMetadata = $this->dm->getClassMetadata($this->class);
// TODO: ODM seems to be missing handling for multiple properties
// $fields = array_map('trim', explode(',', $constraint->property));
$query = $this->getQueryArray($classMetadata, $value, $constraint->property);
$document = $this->findUserBy($query);
if (null === $document) {
return true;
}
// check if document in mongodb is the same document as the checked one
if ($document->isUser($value)) {
return true;
}
// check if returned document is proxy and initialize the minimum identifier if needed
if ($document instanceof Proxy) {
$classMetadata->setIdentifierValue($document, $document->__identifier);
}
// check if document has the same identifier as the current one
if ($classMetadata->getIdentifierValue($document) === $classMetadata->getIdentifierValue($value)) {
return true;
}
return false;
}