Doctrine\ORM\UnitOfWork::loadCollection PHP Method

loadCollection() public method

Initializes (loads) an uninitialized persistent collection of an entity.
public loadCollection ( Doctrine\ORM\PersistentCollection $collection )
$collection Doctrine\ORM\PersistentCollection The collection to initialize.
    public function loadCollection(PersistentCollection $collection)
    {
        $assoc = $collection->getMapping();
        switch ($assoc['type']) {
            case ClassMetadata::ONE_TO_MANY:
                $this->getEntityPersister($assoc['targetEntity'])->loadOneToManyCollection(
                        $assoc, $collection->getOwner(), $collection);
                break;
            case ClassMetadata::MANY_TO_MANY:
                $this->getEntityPersister($assoc['targetEntity'])->loadManyToManyCollection(
                        $assoc, $collection->getOwner(), $collection);
                break;
        }
    }

Usage Example

Example #1
0
 /**
  * @param PersistentCollection $collection
  */
 public function loadCollection(PersistentCollection $collection)
 {
     parent::loadCollection($collection);
     $em = $this->getParentEntityManager();
     foreach ($collection->toArray() as $element) {
         $postLazyloadEventArgs = new PostLazyLoadEventArgs($em, $element);
         $em->getEventManager()->dispatchEvent(PostLazyLoadEventArgs::EVENT_NAME, $postLazyloadEventArgs);
     }
 }