public function resolveJsonField(ClassMetadata $class, DocumentManager $dm, $documentState, $jsonName, $originalData)
{
$uow = $dm->getUnitOfWork();
$couchClient = $dm->getCouchDBClient();
if ($jsonName == 'doctrine_metadata' && isset($originalData['doctrine_metadata']['associations'])) {
foreach ($originalData['doctrine_metadata']['associations'] as $assocName) {
$assocValue = $originalData[$assocName];
if (isset($class->associationsMappings[$assocName])) {
if ($class->associationsMappings[$assocName]['type'] & ClassMetadata::TO_ONE) {
if ($assocValue) {
if ($class->associationsMappings[$assocName]['targetDocument']) {
$assocValue = $dm->getReference($class->associationsMappings[$assocName]['targetDocument'], $assocValue);
} else {
$response = $couchClient->findDocument($assocValue);
if ($response->status == 404) {
$assocValue = null;
} else {
$hints = array();
$assocValue = $uow->createDocument(null, $response->body, $hints);
}
}
}
$documentState[$class->associationsMappings[$assocName]['fieldName']] = $assocValue;
} else {
if ($class->associationsMappings[$assocName]['type'] & ClassMetadata::MANY_TO_MANY) {
if ($class->associationsMappings[$assocName]['isOwning']) {
$documentState[$class->associationsMappings[$assocName]['fieldName']] = new PersistentIdsCollection(new ArrayCollection(), $class->associationsMappings[$assocName]['targetDocument'], $dm, $assocValue);
}
}
}
}
}
}
return $documentState;
}