Doctrine\ODM\MongoDB\UnitOfWork::loadCollection PHP Method

loadCollection() public method

Initializes (loads) an uninitialized persistent collection of a document.
public loadCollection ( Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface $collection )
$collection Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface The collection to initialize.
    public function loadCollection(PersistentCollectionInterface $collection)
    {
        $this->getDocumentPersister(get_class($collection->getOwner()))->loadCollection($collection);
        $this->lifecycleEventManager->postCollectionLoad($collection);
    }

Usage Example

 /** {@inheritdoc} */
 public function initialize()
 {
     if ($this->initialized || !$this->mapping) {
         return;
     }
     $newObjects = array();
     if ($this->isDirty) {
         // Remember any NEW objects added through add()
         $newObjects = $this->coll->toArray();
     }
     $this->initialized = true;
     $this->coll->clear();
     $this->uow->loadCollection($this);
     $this->takeSnapshot();
     $this->mongoData = array();
     // Reattach any NEW objects added through add()
     if ($newObjects) {
         foreach ($newObjects as $key => $obj) {
             if (CollectionHelper::isHash($this->mapping['strategy'])) {
                 $this->coll->set($key, $obj);
             } else {
                 $this->coll->add($obj);
             }
         }
         $this->isDirty = true;
     }
 }
All Usage Examples Of Doctrine\ODM\MongoDB\UnitOfWork::loadCollection
UnitOfWork