loadCollection() public méthode

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.
 /** {@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;
     }
 }
Exemple #2
0
 /**
  * Initializes the collection by loading its contents from the database
  * if the collection is not yet initialized.
  */
 public function initialize()
 {
     if (!$this->initialized && $this->mapping) {
         if ($this->isDirty) {
             // Has NEW objects added through add(). Remember them.
             $newObjects = $this->coll->toArray();
         }
         $this->coll->clear();
         $this->uow->loadCollection($this);
         $this->takeSnapshot();
         // Reattach NEW objects added through add(), if any.
         if (isset($newObjects)) {
             foreach ($newObjects as $key => $obj) {
                 if ($this->mapping['strategy'] === 'set') {
                     $this->coll->set($key, $obj);
                 } else {
                     $this->coll->add($obj);
                 }
             }
             $this->isDirty = true;
         }
         $this->mongoData = array();
         $this->initialized = true;
     }
 }