Doctrine\ODM\MongoDB\DocumentManager::getPartialReference PHP Method

getPartialReference() public method

The returned reference may be a partial object if the document is not yet loaded/managed. If it is a partial object it will not initialize the rest of the document state on access. Thus you can only ever safely access the identifier of a document obtained through this method. The use-cases for partial references involve maintaining bidirectional associations without loading one side of the association or to update a document without loading it. Note, however, that in the latter case the original (persistent) document data will never be visible to the application (especially not event listeners) as it will never be loaded in the first place.
public getPartialReference ( string $documentName, mixed $identifier ) : object
$documentName string The name of the document type.
$identifier mixed The document identifier.
return object The (partial) document reference.
    public function getPartialReference($documentName, $identifier)
    {
        $class = $this->metadataFactory->getMetadataFor(ltrim($documentName, '\\'));
        // Check identity map first, if its already in there just return it.
        if ($document = $this->unitOfWork->tryGetById($identifier, $class)) {
            return $document;
        }
        $document = $class->newInstance();
        $class->setIdentifierValue($document, $identifier);
        $this->unitOfWork->registerManaged($document, $identifier, array());
        return $document;
    }