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; }
public function execute() { $response = $this->doExecute(); if ($this->dm && $this->getParameter('include_docs') === true) { $uow = $this->dm->getUnitOfWork(); foreach ($response->body['rows'] as $k => $v) { if (!isset($v['type']) && !$this->documentName) { throw new \InvalidArgumentException("Cannot query " . $this->getHttpQuery() . " lucene and convert to document instances, " . "the type of document " . $v['id'] . " is not stored in Lucene. You can query without " . "include_docs and pass the ids to findMany() of the repository you know this document is " . "a type of."); } $v['type'] = isset($v['type']) ? $v['type'] : $this->documentName; $doc = $this->dm->find(str_replace(".", "\\", $v['type']), $v['id']); if ($this->onlyDocs) { $response->body['rows'][$k] = $doc; } else { $response->body['rows'][$k]['doc'] = $doc; } } } return $this->createResult($response); }
public function execute() { $response = $this->doExecute(); $data = array(); if ($this->dm && $this->getParameter('include_docs') === true) { $uow = $this->dm->getUnitOfWork(); foreach ($response->body['rows'] as $k => $v) { $doc = $uow->createDocument(null, $v['doc']); if ($this->toArray) { $data[] = $doc; } else { if ($this->onlyDocs) { $response->body['rows'][$k] = $doc; } else { $response->body['rows'][$k]['doc'] = $doc; } } } } return $this->toArray ? $data : $this->createResult($response); }
/** * Find Many documents of the given repositories type by id. * * @param array $ids * @return array */ public function findMany(array $ids, $limit = null, $offset = null) { $uow = $this->dm->getUnitOfWork(); return $uow->findMany($ids, $this->documentName, $limit, $offset); }