Doctrine\ODM\PHPCR\ReferenceManyCollection::initialize PHP Method

initialize() public method

Initializes the collection by loading its contents from the database if the collection is not yet initialized.
public initialize ( )
    public function initialize()
    {
        if (!$this->isInitialized()) {
            $referencedDocs = array();
            if (self::REFERENCE_TYPE_UUID === $this->referenceType) {
                $referencedNodes = $this->dm->getPhpcrSession()->getNodesByIdentifier($this->referencedNodes);
            } else {
                $referencedNodes = $this->dm->getPhpcrSession()->getNodes($this->referencedNodes);
            }
            $uow = $this->dm->getUnitOfWork();
            $uow->getPrefetchHelper()->prefetch($this->dm, $referencedNodes, $this->locale);
            $this->originalReferencePaths = array();
            foreach ($referencedNodes as $referencedNode) {
                $proxy = $uow->getOrCreateProxyFromNode($referencedNode, $this->locale);
                if (isset($targetDocument) && !$proxy instanceof $this->targetDocument) {
                    throw new PHPCRException("Unexpected class for referenced document at '{$referencedNode->getPath()}'. Expected '{$this->targetDocument}' but got '" . ClassUtils::getClass($proxy) . "'.");
                }
                $referencedDocs[] = $proxy;
                $this->originalReferencePaths[] = $referencedNode->getPath();
            }
            $this->collection = new ArrayCollection($referencedDocs);
            $this->initialized = self::INITIALIZED_FROM_PHPCR;
        }
    }