@param array $parentEntities Parent entity classes

@throws \Darvin\AdminBundle\Metadata\MetadataException
325063
private function buildTree(array $parentEntities)
    {
        foreach ($parentEntities as $parentEntity) {
            if (isset($this->entityOverride[$parentEntity])) {
                $parentEntity = $this->entityOverride[$parentEntity];
            }

            $parentMeta = $this->metadata[$parentEntity];
            $parentConfiguration = $parentMeta->getConfiguration();

            foreach ($parentConfiguration['children'] as $key => $childEntity) {
                if (isset($this->entityOverride[$childEntity])) {
                    $childEntity = $this->entityOverride[$childEntity];
                }
                if (!isset($this->metadata[$childEntity])) {
                    unset($parentConfiguration['children'][$key]);

                    continue;
                }

                $childMeta = $this->metadata[$childEntity];
                $associated = false;

                foreach ($childMeta->getMappings() as $property => $mapping) {
                    if (!$childMeta->isAssociation($property)
                        || ($mapping['targetEntity'] !== $parentEntity && !in_array($mapping['targetEntity'], class_parents($parentEntity)))
                    ) {
                        continue;
                    }

                    $childMeta->setParent(new AssociatedMetadata($property, $parentMeta));
                    $parentMeta->addChild(new AssociatedMetadata($property, $childMeta));
                    $associated = true;

                    if (null !== $mapping['inversedBy']) {
                        break;
                    }
                }
                if (!$associated) {
                    throw new MetadataException(
                        sprintf('Entity "%s" is not associated with entity "%s".', $childEntity, $parentEntity)
                    );
                }
            }

            $this->buildTree($parentConfiguration['children']);
        }
    }
302941
protected function indexActionInternal($entities): void {
        $objects = [];
        foreach($entities as $entity) {
            $objects[] = $this->generateEntityAction($entity);
        }
        $outputObject = $this->getOutputObject();
        $blankEntity = $this->generateEntity();
        $outputObject->{$blankEntity->getEntityName() . 's'} = $objects;

        $this->setOutputObject($outputObject);
    }
492235
private function writeCustomParents($fields, ApiInterface $entity) {
        foreach($entity->getCustomParentRelationships() as $customRelationship) {
            $name = $customRelationship->getReferencedFields();
            if(array_key_exists($name, $fields)) {
                $entity->writeAttribute($name, $fields[$name]);
            }
        }
    }
1139582
public void setParentGroupNames(java.util.Collection<String> parentGroupNames) {
        if (parentGroupNames == null) {
            this.parentGroupNames = null;
            return;
        }

        this.parentGroupNames = new java.util.ArrayList<String>(parentGroupNames);
    }
821821
public function updateViability(Elementtype $elementtype, array $parentIds)
    {
        $viabilityRepository = $this->entityManager->getRepository('PhlexibleElementtypeBundle:ElementtypeApply');

        $viabilities = $viabilityRepository->findBy(['elementtypeId' => $elementtype->getId()]);

        foreach ($viabilities as $index => $viability) {
            if (in_array($viability->getUnderElementtypeId(), $parentIds)) {
                unset($parentIds[array_search($viability->getUnderElementtypeId(), $parentIds)]);
                unset($viabilities[$index]);
            }
        }

        foreach ($parentIds as $parentId) {
            $viability = new ElementtypeApply();
            $viability
                ->setElementtypeId($elementtype->getId())
                ->setUnderElementtypeId($parentId);

            $this->entityManager->persist($viability);
        }

        foreach ($viabilities as $viability) {
            $this->entityManager->remove($viability);
        }

        $this->entityManager->flush();
    }
31457
public function setEntitiesAttribute($entities): void
    {
        static::saved(function ($model) use ($entities) {
            $this->entities()->delete();
            ! $entities || $this->entities()->createMany(array_map(function ($entity) {
                return ['entity_type' => $entity];
            }, $entities));
        });
    }
1221647
protected function setRelationDefine($parent)
    {
        $this->changeRelationModel();
        $this->setDefineValues($this->defineValues);
        $this->relations['thumbnails']['datas'] = $parent->thumbnails()->get(['slug','photo_width','photo_height'])->toArray();
        $this->relations['extras']['datas'] = $parent->extras()->get(['name','type'])->toArray();
        $this->setOperationRelation($this->relations);
    }
223308
public function removeAll(array $entities): void
    {
        if ([] === $entities) {
            return;
        }
        foreach ($entities as $entity) {
            $this->checkIsCorrectEntityType($entity);
            $this->entityManager->remove($entity);
        }

        $this->entityManager->flush();
    }
1366572
public function parentRelations(array $relations): ModelList
    {
        $this->main['parents'] = [];

        foreach ($relations as $key => $value) {

            if (is_string($key)) {
                $parent = [
                    'relation' => $key,
                    'field'    => $value,
                ];
            } else {
                $parent = [
                    'relation' => $value,
                    'field'    => $value,
                ];
            }

            $this->main['parents'][] = $parent;
        }

        return $this;
    }
592809
protected function loadParentMetadata(ClassMetadataInterface $metadata)
    {
        $parent = $metadata->getReflectionClass()->getParentClass();

        if ($parent) {
            $metadata->mergeRules($this->getClassMetadata($parent->getName()));
        }
    }
368088
private function convertClassAnnotationsToClassMetadata(
        array $classAnnotations,
        ReflectionClass $reflectionClass,
        Mapping\ClassMetadata $parent
    ) {
        switch (true) {
            case isset($classAnnotations[Annotation\Entity::class]):
                return $this->convertClassAnnotationsToEntityClassMetadata(
                    $classAnnotations,
                    $reflectionClass,
                    $parent
                );

                break;

            case isset($classAnnotations[Annotation\MappedSuperclass::class]):
                return $this->convertClassAnnotationsToMappedSuperClassMetadata(
                    $classAnnotations,
                    $reflectionClass,
                    $parent
                );
            case isset($classAnnotations[Annotation\Embeddable::class]):
                return $this->convertClassAnnotationsToEntityClassMetadata(
                    $classAnnotations,
                    $reflectionClass,
                    $parent
                );
            default:
                throw Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass($reflectionClass->getName());
        }
    }
389855
private function addInheritedFields(ClassMetadata $subClass, ClassMetadata $parentClass) : void
    {
        foreach ($parentClass->fieldMappings as $fieldName => $mapping) {
            if (! isset($mapping['inherited']) && ! $parentClass->isMappedSuperclass) {
                $mapping['inherited'] = $parentClass->name;
            }
            if (! isset($mapping['declared'])) {
                $mapping['declared'] = $parentClass->name;
            }
            $subClass->addInheritedFieldMapping($mapping);
        }
        foreach ($parentClass->reflFields as $name => $field) {
            $subClass->reflFields[$name] = $field;
        }
    }
650334
public function addParents($term_id, array $parent_ids)
    {
        $this->testCanAddParents($term_id, count($parent_ids));

        foreach ($parent_ids as $id) {
            $this->termHierarchyRepository->addParent($term_id, $id);
        }
    }
882132
public function add_objects( $type, array $objects, $parent = null ) {
		foreach ( $objects as $slug => $struct ) {
			if ( is_array( $struct ) ) {
				$this->add( $type, $slug, $struct, $parent );
			}
		}
	}
1220839
public function createEntity(string $entity_id, array $parents)
    {
        $entity = new Entity($this, $entity_id, $parents);
        return $entity;
    }
916370
public function setParentEntity($parentEntity)
    {
        if (!$parentEntity instanceof Entity && null !== $parentEntity) {
            throw new \InvalidArgumentException('The attribute parentEntity on the class Entity has to be Entity or null (' . gettype($parentEntity) . ('object' === gettype($parentEntity) ? ' ' . get_class($parentEntity) : '') . ' given).');
        }

        $this->parentEntity = $parentEntity;

        return $this;
    }
1249670
private function getDeletionPreventingParents() {
        $parentEntities = array();
        foreach($this->getModelBuilder()->getRelationships() as $relationship) {
            if($relationship->isPlural() && !$relationship->isNullable() && $relationship->getAction() != 'ACTION_CASCADE') {
                $parentEntities[] = $relationship->getAlias();
            }
        }

        return $parentEntities;
    }