Set the document level options of the parent class to the subclass.

This has to be done before loading the data of the subclass.

@param ClassMetadata $subClass
@param ClassMetadata $parentClass
439673
private function addInheritedDocumentOptions(ClassMetadata $subClass, ClassMetadata $parentClass)
    {
        $subClass->setCustomRepositoryClassName($parentClass->customRepositoryClassName);
        $subClass->setTranslator($parentClass->translator);
        $subClass->setVersioned($parentClass->versionable);
        $subClass->setReferenceable($parentClass->referenceable);
        $subClass->setNodeType($parentClass->getNodeType());
    }
679344
private function cascadePostUpdateAndPostPersist(ClassMetadata $class, $document)
    {
        $hasPostPersistListeners = $this->evm->hasListeners(Events::postPersist);
        $hasPostUpdateListeners = $this->evm->hasListeners(Events::postUpdate);

        foreach ($class->fieldMappings as $mapping) {
            if (isset($mapping['embedded'])) {
                $value = $class->reflFields[$mapping['fieldName']]->getValue($document);
                if ($value === null) {
                    continue;
                }
                if ($mapping['type'] === 'one') {
                    $value = array($value);
                }
                foreach ($value as $entry) {
                    $entryOid = spl_object_hash($entry);
                    $entryClass = $this->dm->getClassMetadata(get_class($entry));
                    if ( ! isset($this->documentChangeSets[$entryOid])) {
                        continue;
                    }
                    if (isset($this->documentInsertions[$entryOid])) {
                        if ( ! empty($entryClass->lifecycleCallbacks[Events::postPersist])) {
                            $entryClass->invokeLifecycleCallbacks(Events::postPersist, $entry);
                        }
                        if ($hasPostPersistListeners) {
                            $this->evm->dispatchEvent(Events::postPersist, new LifecycleEventArgs($entry, $this->dm));
                        }
                    } else {
                        if ( ! empty($entryClass->lifecycleCallbacks[Events::postUpdate])) {
                            $entryClass->invokeLifecycleCallbacks(Events::postUpdate, $entry);
                            $this->recomputeSingleDocumentChangeSet($entryClass, $entry);
                        }
                        if ($hasPostUpdateListeners) {
                            $this->evm->dispatchEvent(Events::postUpdate, new LifecycleEventArgs($entry, $this->dm));
                        }
                    }
                    $this->cascadePostUpdateAndPostPersist($entryClass, $entry);
                }
            }
        }
    }
330703
public function setParentSection($parentSection)
	{
		if($this->parentSection !== $parentSection) {
			if($this->parentSection) {
				$this->parentSection->getSectionConfig()->removeNextSection($this->getParentDocument());
			}
			$this->parentSection = $parentSection;
			if($parentSection) {
				$parentSection->getSectionConfig()->addNextSection($this->getParentDocument());
			}
		}
		return $this;
	}
830854
private function addInheritedSqlResultSetMappings(ClassMetadata $subClass, ClassMetadata $parentClass)
    {
        foreach ($parentClass->sqlResultSetMappings as $name => $mapping) {
            if ( ! isset ($subClass->sqlResultSetMappings[$name])) {
                $entities = array();
                foreach ($mapping['entities'] as $entity) {
                    $entities[] = array(
                        'fields'                => $entity['fields'],
                        'isSelfClass'           => $entity['isSelfClass'],
                        'discriminatorColumn'   => $entity['discriminatorColumn'],
                        'entityClass'           => $entity['isSelfClass'] ? $subClass->name : $entity['entityClass'],
                    );
                }

                $subClass->addSqlResultSetMapping(array(
                    'name'          => $mapping['name'],
                    'columns'       => $mapping['columns'],
                    'entities'      => $entities,
                ));
            }
        }
    }
538760
final public function internalSetParent(ParentNodeInterface $parent)
    {
        $this->emit('parent.change', [$parent, $this]);
        $this->parentNode = $parent;
    }
58757
private function addInheritedNamedNativeQueries(ClassMetadata $subClass, ClassMetadata $parentClass)
    {
        foreach ($parentClass->namedNativeQueries as $name => $query) {
            if ( ! isset ($subClass->namedNativeQueries[$name])) {
                $subClass->addNamedNativeQuery(array(
                    'name'              => $query['name'],
                    'query'             => $query['query'],
                    'isSelfClass'       => $query['isSelfClass'],
                    'resultSetMapping'  => $query['resultSetMapping'],
                    'resultClass'       => $query['isSelfClass'] ? $subClass->name : $query['resultClass'],
                ));
            }
        }
    }
1216973
public function setParentClasses(array $classNames) : void
    {
        $this->parentClasses = $classNames;

        if (count($classNames) <= 0) {
            return;
        }

        $this->rootDocumentName = (string) array_pop($classNames);
    }
1248937
public function setParent(Page $parent)
    {
        $this->parent = $parent;

        $this->parentId = $parent->getPageId();
    }
600553
public static void setMetaClass(Class self, MetaClass metaClass) {
        final MetaClassRegistry metaClassRegistry = GroovySystem.getMetaClassRegistry();
        if (metaClass == null)
            metaClassRegistry.removeMetaClass(self);
        else {
            if (metaClass instanceof HandleMetaClass) {
                metaClassRegistry.setMetaClass(self, ((HandleMetaClass)metaClass).getAdaptee());
            } else {
                metaClassRegistry.setMetaClass(self, metaClass);
            }
            if (self==NullObject.class) {
                NullObject.getNullObject().setMetaClass(metaClass);
            }
        }
    }
397744
public function setParentClasses(array $classNames)
    {
        $this->parentClasses = $classNames;
        if (count($classNames) > 0) {
            $this->rootXmlEntityName = array_pop($classNames);
        }
    }
584462
protected function validateRuntimeMetadata(ClassMetadata $class, ?ClassMetadata $parent = null) : void
    {
        if (! $class->getReflectionClass()) {
            // only validate if there is a reflection class instance
            return;
        }

        $class->validateIdentifier();
        $class->validateAssociations();
        $class->validateLifecycleCallbacks($this->getReflectionService());

        // verify inheritance
        if (! $class->isMappedSuperclass && $class->inheritanceType !== InheritanceType::NONE) {
            if (! $parent) {
                if (! $class->discriminatorMap) {
                    throw MappingException::missingDiscriminatorMap($class->getClassName());
                }

                if (! $class->discriminatorColumn) {
                    throw MappingException::missingDiscriminatorColumn($class->getClassName());
                }
            }
        } elseif (($class->discriminatorMap || $class->discriminatorColumn) && $class->isMappedSuperclass && $class->isRootEntity()) {
            // second condition is necessary for mapped superclasses in the middle of an inheritance hierarchy
            throw MappingException::noInheritanceOnMappedSuperClass($class->getClassName());
        }
    }
688325
private function addInheritedIndexes(ClassMetadata $subClass, ClassMetadata $parentClass)
    {
        if (! $parentClass->isMappedSuperclass) {
            return;
        }

        foreach (array('uniqueConstraints', 'indexes') as $indexType) {
            if (isset($parentClass->table[$indexType])) {
                foreach ($parentClass->table[$indexType] as $indexName => $index) {
                    if (isset($subClass->table[$indexType][$indexName])) {
                        continue; // Let the inheriting table override indices
                    }

                    $subClass->table[$indexType][$indexName] = $index;
                }
            }
        }
    }
914223
public function setMetadataClass(string $metadataClass): void
    {
        if (! class_exists($metadataClass) || ! (new \ReflectionClass($metadataClass))->implementsInterface(ClassMetadataInterface::class)) {
            throw InvalidArgumentException::create(InvalidArgumentException::INVALID_METADATA_CLASS, $metadataClass);
        }

        $this->metadataClass = $metadataClass;
    }
846245
public function setParent($parent, $from)
    {
        $this->parents()->set($parent, $parent instanceof Document ? $from : '*');
        return $this;
    }
506764
protected function doLoadMetadata($class, $parent, $rootEntityFound, array $nonSuperclassParents)
    {
        //Manipulates $classMetadata;
        $this->driver->loadMetadataForClass($class->getName(), $class);

        if ($this->evm->hasListeners(Events::loadClassMetadata)) {
            $eventArgs = new LoadClassMetadataEventArgs($class, $this->sm);
            $this->evm->dispatchEvent(Events::loadClassMetadata, $eventArgs);
        }
    }
1305009
private function cascadePreUpdate(ClassMetadata $class, $document)
    {
        $hasPreUpdateListeners = $this->evm->hasListeners(Events::preUpdate);

        foreach ($class->fieldMappings as $mapping) {
            if (isset($mapping['embedded'])) {
                $value = $class->reflFields[$mapping['fieldName']]->getValue($document);
                if ($value === null) {
                    continue;
                }
                if ($mapping['type'] === 'one') {
                    $value = array($value);
                }
                foreach ($value as $entry) {
                    $entryOid = spl_object_hash($entry);
                    $entryClass = $this->dm->getClassMetadata(get_class($entry));
                    if ( ! isset($this->documentChangeSets[$entryOid])) {
                        continue;
                    }
                    if ( ! isset($this->documentInsertions[$entryOid])) {
                        if ( ! empty($entryClass->lifecycleCallbacks[Events::preUpdate])) {
                            $entryClass->invokeLifecycleCallbacks(Events::preUpdate, $entry);
                            $this->recomputeSingleDocumentChangeSet($entryClass, $entry);
                        }
                        if ($hasPreUpdateListeners) {
                            $this->evm->dispatchEvent(Events::preUpdate, new Event\PreUpdateEventArgs(
                                $entry, $this->dm, $this->documentChangeSets[$entryOid])
                            );
                        }
                    }
                    $this->cascadePreUpdate($entryClass, $entry);
                }
            }
        }
    }
1215001
public function loadMetadataForClass($className, ClassMetadataInterface $class)
    {
        /** @var $class ClassMetadata */
        $reflection     = $class->getReflectionClass();
        $documentAnnots = [];
        $indexes        = [];

        //class annotations
        $classAnnotations = $this->reader->getClassAnnotations($reflection);
        foreach ($classAnnotations as $annot) {
            //document annotations
            $classAnnotations[get_class($annot)] = $annot;

            foreach ($this->entityAnnotationClasses as $annotClass => $i) {
                if ($annot instanceof $annotClass) {
                    $documentAnnots[$i] = $annot;
                    continue 2;
                }
            }

            //non-document class annotations
            if ($annot instanceof ODM\Discriminator) {
                if ($annot->attribute !== null) {
                    $class->setDiscriminatorAttribute($annot->attribute);
                }
                if ($annot->map !== null) {
                    $class->setDiscriminatorMap($annot->map);
                }
                if ($annot->defaultValue !== null) {
                    $class->setDiscriminatorDefaultValue($annot->defaultValue);
                }
            } elseif ($annot instanceof ODM\InheritanceType) {
                $class->setInheritanceType(constant(ClassMetadata::class . '::INHERITANCE_TYPE_' . $annot->value));
            } elseif ($annot instanceof ODM\Index) {
                $indexes[$annot->name]['projectionType'] = $annot->projectionType;
                $indexes[$annot->name]['readCapacity']   = $annot->readCapacity;
                $indexes[$annot->name]['writeCapacity']  = $annot->writeCapacity;
            } elseif ($annot instanceof ODM\ChangeTrackingPolicy) {
                $class->setChangeTrackingPolicy(constant(ClassMetadata::class . '::CHANGETRACKING_' . $annot->value));
            }
        }

        if (!$documentAnnots) {
            throw new MappingExceptionClassNotMapped($className);
        }

        //find the winning document annotation
        ksort($documentAnnots);
        $documentAnnot = reset($documentAnnots);

        if ($documentAnnot instanceof ODM\MappedSuperclass) {
            $class->isMappedSuperclass = true;
        } elseif ($documentAnnot instanceof ODM\EmbeddedDocument) {
            $class->isEmbeddedDocument = true;
        }
        if (isset($documentAnnot->table)) {
            $class->setTable($documentAnnot->table);
        }
        if (isset($documentAnnot->repositoryClass) && !$class->isEmbeddedDocument) {
            $class->setCustomRepositoryClass($documentAnnot->repositoryClass);
        }
        if (isset($documentAnnot->requireIndexes)) {
            $class->setRequireIndexes($documentAnnot->requireIndexes);
        }
        if (!empty($documentAnnot->readOnly)) {
            $class->markReadOnly();
        }

        //property annotations
        $propertyFactory = new PropertyMetadataFactory($class);
        foreach ($reflection->getProperties() as $property) {
            if (!$this->propertyNeedsMapping($class, $property)) {
                continue;
            }

            $mapping        = $propertyFactory->create($property->getName());
            $attributeAnnot = null;

            foreach ($this->reader->getPropertyAnnotations($property) as $annot) {
                if ($annot instanceof ODM\AbstractAttribute) {
                    $attributeAnnot         = true;
                    $mapping->attributeName = $annot->name;

                    if ($annot instanceof ODM\NotSaved) {
                        $mapping->notSaved = true;
                        continue;
                    }

                    $mapping->nullable = $annot->nullable;
                    $mapping->strategy = $annot->strategy;
                    $mapping->type     = $annot->type;

                    if ($class->isEmbeddedDocument && $mapping->strategy === PropertyMetadata::STORAGE_STRATEGY_ADD_TO_SET) {
                        throw MappingException::addToSetOnEmbeddedDocument($class->name, $property->getName());
                    }

                    if ($annot instanceof ODM\AbstractEmbed) {
                        $mapping->embedded       = $annot->embedded;
                        $mapping->targetDocument = $annot->targetDocument;

                        if ($annot instanceof ODM\EmbedMany) {
                            $mapping->collectionClass = $annot->collectionClass;
                        }
                    } elseif ($annot instanceof ODM\AbstractReference) {
                        $mapping->criteria         = $annot->criteria;
                        $mapping->inversedBy       = $annot->inversedBy;
                        $mapping->mappedBy         = $annot->mappedBy;
                        $mapping->mappedIndex      = $annot->mappedIndex;
                        $mapping->orphanRemoval    = $annot->orphanRemoval;
                        $mapping->reference        = $annot->reference;
                        $mapping->requireIndexes   = $annot->requireIndexes;
                        $mapping->repositoryMethod = $annot->repositoryMethod;
                        $mapping->storeAs          = $annot->storeAs;
                        $mapping->targetDocument   = $annot->targetDocument;

                        if ($annot instanceof ODM\ReferenceMany) {
                            $mapping->limit           = $annot->limit;
                            $mapping->prime           = $annot->prime;
                            $mapping->collectionClass = $annot->collectionClass;

                            if ($annot->order === PropertyMetadata::ORDER_REVERSE) {
                                $mapping->reverse = true;
                            }
                        }

                        $mapping->setCascades((array)$annot->cascade);
                    }
                } elseif ($annot instanceof ODM\HashKey) {
                    $indexes[$annot->index]['hashKey'] = new HashKey($mapping);
                } elseif ($annot instanceof ODM\RangeKey) {
                    $indexes[$annot->index]['rangeKey'] = new RangeKey($mapping);
                } elseif ($annot instanceof ODM\Project) {
                    $value = (array)$annot->value;

                    if (count($value) === 0) {
                        //if no name is specified the primary index is assumed
                        $indexes[null]['projectionAttributes'][] = $property->getName();
                    } else {
                        foreach ($value as $indexName) {
                            $indexes[$indexName]['projectionAttributes'][] = $property->getName();
                        }
                    }
                } elseif ($annot instanceof ODM\GeneratedValue) {
                    $mapping->generatorStrategy = $annot->strategy;
                    $mapping->generatorOptions  = $annot->options;
                } elseif ($annot instanceof ODM\Discriminator) {
                    $mapping->discriminatorAttribute    = $annot->attribute;
                    $mapping->discriminatorMap          = $annot->map;
                    $mapping->discriminatorDefaultValue = $annot->defaultValue;
                } elseif ($annot instanceof ODM\AlsoLoad) {
                    $mapping->alsoLoadAttributes = (array)$annot->value;
                } elseif ($annot instanceof ODM\Version) {
                    $mapping->version = true;
                } elseif ($annot instanceof ODM\Lock) {
                    $mapping->lock = true;
                } elseif ($annot instanceof ODM\ChangeTrackingPolicy) {
                    $class->setChangeTrackingPolicy(constant(ClassMetadata::class . '::CHANGETRACKING_' . $annot->value));
                }
            }

            if ($attributeAnnot) {
                $mapping->mapAttribute($class);
            }
        }

        //method annotations
        foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
            /* Filter for the declaring class only. Callbacks from parent
             * classes will already be registered.
             */
            if ($method->getDeclaringClass()->name !== $reflection->name) {
                continue;
            }

            foreach ($this->reader->getMethodAnnotations($method) as $annot) {
                if ($annot instanceof ODM\AlsoLoad) {
                    $class->registerAlsoLoadMethod($method->getName(), $annot->value);
                }

                if (!isset($classAnnotations[ODM\HasLifecycleCallbacks::class])) {
                    continue;
                }

                if ($annot instanceof ODM\PrePersist) {
                    $class->addLifecycleCallback($method->getName(), Event::prePersist);
                } elseif ($annot instanceof ODM\PostPersist) {
                    $class->addLifecycleCallback($method->getName(), Event::postPersist);
                } elseif ($annot instanceof ODM\PreUpdate) {
                    $class->addLifecycleCallback($method->getName(), Event::preUpdate);
                } elseif ($annot instanceof ODM\PostUpdate) {
                    $class->addLifecycleCallback($method->getName(), Event::postUpdate);
                } elseif ($annot instanceof ODM\PreRemove) {
                    $class->addLifecycleCallback($method->getName(), Event::preRemove);
                } elseif ($annot instanceof ODM\PostRemove) {
                    $class->addLifecycleCallback($method->getName(), Event::postRemove);
                } elseif ($annot instanceof ODM\PreLoad) {
                    $class->addLifecycleCallback($method->getName(), Event::preLoad);
                } elseif ($annot instanceof ODM\PostLoad) {
                    $class->addLifecycleCallback($method->getName(), Event::postLoad);
                } elseif ($annot instanceof ODM\PreFlush) {
                    $class->addLifecycleCallback($method->getName(), Event::preFlush);
                }
            }
        }

        //indexes
        $indexFactory = new IndexFactory($class);
        foreach ($indexes as $name => $annot) {
            $primary = $name === '';

            //create index, merging values collected from annotations with defaults
            $opts                  = array_fill_keys(['hashKey', 'rangeKey', 'projectionType', 'projectionAttributes'], null);
            $opts['readCapacity']  = IndexFactory::DEFAULT_READ_CAPACITY;
            $opts['writeCapacity'] = IndexFactory::DEFAULT_WRITE_CAPACITY;
            $opts                  = array_merge($opts, $annot);

            $index = $indexFactory->create(
                $primary ? null : $name,
                $opts['hashKey'],
                $opts['rangeKey'],
                $opts['projectionType'],
                $opts['projectionAttributes'],
                $opts['readCapacity'],
                $opts['writeCapacity']
            );

            if ($primary === true) {
                $class->setIndex($index);
            } else {
                $class->addSecondaryIndex($index);
            }
        }
    }