Doctrine\ODM\MongoDB\Persisters\CollectionPersister::delete PHP Method

delete() public method

Deletes a PersistentCollection instance completely from a document using $unset.
public delete ( PersistentCollection $coll, array $options )
$coll Doctrine\ODM\MongoDB\PersistentCollection
$options array
    public function delete(PersistentCollection $coll, array $options)
    {
        list($propertyPath, $parent) = $this->getPathAndParent($coll);
        $query = array($this->cmd . 'unset' => array($propertyPath => true));
        $this->executeQuery($parent, $query, $options);
    }

Usage Example

 private function handleCollections($document, $options)
 {
     // Collection deletions (deletions of complete collections)
     foreach ($this->uow->getScheduledCollections($document) as $coll) {
         if ($this->uow->isCollectionScheduledForDeletion($coll)) {
             $this->cp->delete($coll, $options);
         }
     }
     // Collection updates (deleteRows, updateRows, insertRows)
     foreach ($this->uow->getScheduledCollections($document) as $coll) {
         if ($this->uow->isCollectionScheduledForUpdate($coll)) {
             $this->cp->update($coll, $options);
         }
     }
     // Take new snapshots from visited collections
     foreach ($this->uow->getVisitedCollections($document) as $coll) {
         $coll->takeSnapshot();
     }
 }