Doctrine\ODM\MongoDB\DocumentManager::detach PHP Method

detach() public method

Documents which previously referenced the detached document will continue to reference it.
public detach ( object $document )
$document object The document to detach.
    public function detach($document)
    {
        if (!is_object($document)) {
            throw new \InvalidArgumentException(gettype($document));
        }
        $this->unitOfWork->detach($document);
    }

Usage Example

 /**
  * Bulk generates and inserts full version records for the provided versionable entities
  * in MongoDB.
  * Return an array of ids of documents that have really changed since the last version.
  *
  * @param array $versionables
  *
  * @return array
  */
 public function bulkPersist(array $versionables)
 {
     $versions = [];
     $changedDocIds = [];
     $author = VersionManager::DEFAULT_SYSTEM_USER;
     $event = $this->eventDispatcher->dispatch(BuildVersionEvents::PRE_BUILD, new BuildVersionEvent());
     if (null !== $event && null !== $event->getUsername()) {
         $author = $event->getUsername();
     }
     foreach ($versionables as $versionable) {
         $previousVersion = $this->getPreviousVersion($versionable);
         $context = $this->versionContext->getContextInfo(get_class($versionable));
         $newVersion = $this->versionBuilder->buildVersion($versionable, $author, $previousVersion, $context);
         if (count($newVersion->getChangeSet()) > 0) {
             $versions[] = $newVersion;
             $changedDocIds[] = $versionable->getId();
         }
         if (null !== $previousVersion) {
             $this->documentManager->detach($previousVersion);
         }
     }
     $mongodbVersions = [];
     foreach ($versions as $version) {
         $mongodbVersions[] = $this->normalizer->normalize($version, VersionNormalizer::FORMAT);
     }
     if (count($mongodbVersions) > 0) {
         $collection = $this->documentManager->getDocumentCollection($this->versionClass);
         $collection->batchInsert($mongodbVersions);
     }
     return $changedDocIds;
 }
All Usage Examples Of Doctrine\ODM\MongoDB\DocumentManager::detach