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); } } }