private function purgeChildren($document)
    {
        if ($document instanceof Proxy && !$document->__isInitialized()) {
            return;
        }

        $class = $this->dm->getClassMetadata(get_class($document));
        foreach ($class->childMappings as $fieldName) {
            $child = $class->reflFields[$fieldName]->getValue($document);
            if ($child !== null) {
                $this->purgeChildren($child);
                $this->unregisterDocument($child);
            }
        }
    }
private function purgeChildren($document)
    {
        if ($document instanceof Proxy && !$document->__isInitialized()) {
            return;
        }

        $class = $this->dm->getClassMetadata(get_class($document));
        foreach ($class->childMappings as $fieldName) {
            $child = $class->reflFields[$fieldName]->getValue($document);
            if ($child !== null) {
                $this->purgeChildren($child);
                $this->unregisterDocument($child);
            }
        }
    }
private function purgeChildren ( $ document ) { if ( $ document instanceof Proxy && ! $ document -> __isInitialized ( ) ) { return ; } $ class = $ this -> dm -> getClassMetadata ( get_class ( $ document ) ) ; foreach ( $ class -> childMappings as $ fieldName ) { $ child = $ class -> reflFields [ $ fieldName ] -> getValue ( $ document ) ; if ( $ child !== null ) { $ this -> purgeChildren ( $ child ) ; $ this -> unregisterDocument ( $ child ) ; } } }
recurse over all known child documents to remove them form this unit of work
as their parent gets removed from phpcr. If you do not, flush will try to create
orphaned nodes if these documents are modified which leads to a PHPCR exception.

@param object $document
recurse over all known child documents to remove them form this unit of work as their parent gets removed from phpcr . If you do not flush will try to create orphaned nodes if these documents are modified which leads to a PHPCR exception .