@param PersistenceContext $context
@param ParentChildMap     $map

@return void
499417
protected function insertRelated(PersistenceContext $context, ParentChildMap $map)
    {
        $primaryKey = $map->getPrimaryKeyColumn();
        /** @var Row[] $parents */
        $parents = [];
        /** @var array $children */
        $children = [];

        foreach ($map->getItems() as $key => $item) {
            $parents[$key]  = $item->getParent();
            $children[$key] = $item->getChild();
        }

        $rows = $this->reference->syncRelated($context, [$this->foreignKeyColumn], $children);

        $selfReferencingChildRows = [];

        foreach ($rows as $key => $row) {
            $parent = $parents[$key];

            if ($parent->hasColumn($primaryKey)) {
                $this->setForeignKey([$row], $this->foreignKeyToParent, $parent->getColumn($primaryKey));
            } else {
                $parent->onInsertPrimaryKey(function ($id) use ($row) {
                    $this->setForeignKey([$row], $this->foreignKeyToParent, $id);
                });

                if ($parent === $row) {
                    $selfReferencingChildRows[] = $row;
                }
            }
        }

        if ($selfReferencingChildRows) {
            // If the rows are self-referencing and need to be inserted
            // an extra step must be taken because the primary key will
            // only be known after inserting so the foreign key to itself
            // will have to be updated separately afterwards
            $context->bulkUpdate(new RowSet($this->relatedTable->withColumnsButIgnoringConstraints([
                $this->relatedPrimaryKey,
                $this->foreignKeyColumn,
            ]), $selfReferencingChildRows));
        }
    }
1253189
protected function insertRelated(PersistenceContext $context, ParentChildrenMap $map)
    {
        $primaryKey = $map->getPrimaryKeyColumn();
        /** @var Row[] $parents */
        $parents = [];
        /** @var object[] $children */
        $children          = [];
        $childRows         = [];
        $childKeyParentMap = [];

        foreach ($map->getItems() as $key => $item) {
            $parents[$key] = $item->getParent();

            foreach ($item->getChildren() as $childKey => $child) {
                $uniqueKey                     = $key . '|' . $childKey;
                $children[$uniqueKey]          = $child;
                $childKeyParentMap[$uniqueKey] = $key;
                $childRows[$uniqueKey]         = new Row($this->childrenTable);
            }
        }

        // Since all the rows are deleted then reinserted, we have to disable lazy loading
        // for all child relations as these will have been deleted via the foreign key
        // and need to be re-inserted
        $this->disableLazyLoadingForRelations(function () use ($context, $children, $childRows) {
            $this->mapper->persistAllToRows($context, $children, $childRows);
        });

        $rowGroups = [];

        foreach ($childKeyParentMap as $rowKey => $parentKey) {
            $rowGroups[$parentKey][] = $childRows[$rowKey];
        }

        foreach ($map->getItems() as $key => $item) {
            $parentRow = $item->getParent();
            $childRows = isset($rowGroups[$key]) ? $rowGroups[$key] : [];

            if ($parentRow->hasColumn($primaryKey)) {
                $this->setForeignKey($childRows, $this->foreignKeyToParent->getName(), $parentRow->getColumn($primaryKey));
            } else {
                $parentRow->onInsertPrimaryKey(function ($id) use ($childRows) {
                    $this->setForeignKey($childRows, $this->foreignKeyToParent->getName(), $id);
                });
            }
        }
    }
598167
public void replaceMapChildren(Map<String, String> map, String parentId) {
		ArrayList<StringEntity> entities = new ArrayList<>();
		for (String key : map.keySet()) {
			StringEntity entity = new StringEntity();
			entity.setParentId(parentId);
			entity.setId(key);
			entity.setValue(map.get(key));
			entities.add(entity);
		}
		replaceChildren(entities, parentId);
	}
732293
public static function mapDescendantsArray(Tree $parent, Array $map)
    {
        foreach ($map as $item) {
            $node = new static($item);
            $node->setChildOf($parent);
            if (isset($item['children'])) {
                static::mapDescendantsArray($node, $item['children']);
            }
        }

    }
848534
private function computeAssociationChanges($parentDocument, $mapping, $value)
    {
        $isNewParentDocument = isset($this->documentInsertions[spl_object_hash($parentDocument)]);
        $class = $this->dm->getClassMetadata(get_class($parentDocument));
        $topOrExistingDocument = ( ! $isNewParentDocument || ! $class->isEmbeddedDocument);

        if ($value instanceof PersistentCollection && $value->isDirty() && $mapping['isOwningSide']) {
            if ($topOrExistingDocument || strncmp($mapping['strategy'], 'set', 3) === 0) {
                if ( ! in_array($value, $this->collectionUpdates, true)) {
                    $this->collectionUpdates[] = $value;
                }
            }
            $this->visitedCollections[] = $value;
        }

        if ( ! $mapping['isCascadePersist']) {
            return; // "Persistence by reachability" only if persist cascade specified
        }

        if ($mapping['type'] === 'one') {
            if ($value instanceof Proxy && ! $value->__isInitialized__) {
                return; // Ignore uninitialized proxy objects
            }
            $value = array($value);
        } elseif ($value instanceof PersistentCollection) {
            $value = $value->unwrap();
        }
        $count = 0;
        foreach ($value as $key => $entry) {
            $targetClass = $this->dm->getClassMetadata(get_class($entry));
            $state = $this->getDocumentState($entry, self::STATE_NEW);

            // Handle "set" strategy for multi-level hierarchy
            $pathKey = $mapping['strategy'] !== 'set' ? $count : $key;
            $path = $mapping['type'] === 'many' ? $mapping['name'] . '.' . $pathKey : $mapping['name'];

            $count++;
            if ($state == self::STATE_NEW) {
                if ( ! $mapping['isCascadePersist']) {
                    throw new \InvalidArgumentException("A new document was found through a relationship that was not"
                        . " configured to cascade persist operations: " . self::objToStr($entry) . "."
                        . " Explicitly persist the new document or configure cascading persist operations"
                        . " on the relationship.");
                }
                $this->persistNew($targetClass, $entry);
                $this->setParentAssociation($entry, $mapping, $parentDocument, $path);
                $this->computeChangeSet($targetClass, $entry);
            } elseif ($state == self::STATE_MANAGED && $targetClass->isEmbeddedDocument) {
                $this->setParentAssociation($entry, $mapping, $parentDocument, $path);
                $this->computeChangeSet($targetClass, $entry);
            } elseif ($state == self::STATE_REMOVED) {
                throw new \InvalidArgumentException("Removed document detected during flush: "
                    . self::objToStr($entry) . ". Remove deleted documents from associations.");
            } elseif ($state == self::STATE_DETACHED) {
                // Can actually not happen right now as we assume STATE_NEW,
                // so the exception will be raised from the DBAL layer (constraint violation).
                throw new \InvalidArgumentException("A detached document was found through a "
                    . "relationship during cascading a persist operation.");
            }
        }
    }
1214870
public function delete(PersistenceContext $context, Delete $parentDelete)
    {
        $this->mode->removeRelationsQuery(
            $context,
            $this->mapper,
            $parentDelete,
            $this->childrenTable,
            $this->foreignKeyToParent,
            $parentDelete->getTable()->getPrimaryKeyColumn()
        );
    }
390873
public void setMap(Map<String, Object> map) {
        eventMap.clear();
        eventMap.putAll(map);
    }
503030
protected function getDataFromMap(ParentChildMap $map) : array
    {
        /** @var Row[] $parentRows */
        $parentRows = [];
        /** @var object[] $children */
        $children = [];

        foreach ($map->getItems() as $key => $item) {
            if ($item->getChild()) {
                $parentRows[$key] = $item->getParent();
                $children[$key]   = $item->getChild();
            }
        }

        return array($parentRows, $children);
    }
752825
public function loadCollection(PersistentCollectionInterface $collection) : void
    {
        if ($collection->getOwner() === null) {
            throw PersistentCollectionException::ownerRequiredToLoadCollection();
        }

        $this->getDocumentPersister(get_class($collection->getOwner()))->loadCollection($collection);
        $this->lifecycleEventManager->postCollectionLoad($collection);
    }
16207
public function loadCollection(PersistentCollectionInterface $collection) : void
    {
        $mapping = $collection->getMapping();
        switch ($mapping['association']) {
            case ClassMetadata::EMBED_MANY:
                $this->loadEmbedManyCollection($collection);
                break;

            case ClassMetadata::REFERENCE_MANY:
                if (isset($mapping['repositoryMethod']) && $mapping['repositoryMethod']) {
                    $this->loadReferenceManyWithRepositoryMethod($collection);
                } else {
                    if ($mapping['isOwningSide']) {
                        $this->loadReferenceManyCollectionOwningSide($collection);
                    } else {
                        $this->loadReferenceManyCollectionInverseSide($collection);
                    }
                }
                break;
        }
    }
1135563
private void addChildModelsToMap(PMML4Model parentModel) {
        Map<String, PMML4Model> childModels = parentModel.getChildModels();
        if (childModels != null && !childModels.isEmpty()) {
            for (PMML4Model model : childModels.values()) {
                modelsMap.put(model.getModelId(), model);
                addChildModelsToMap(model);
            }
        }
    }
1175688
final protected function persistChildrenIgnoringBidirectionalRelation(
            PersistenceContext $context,
            array $children
    ) : array {
        $bidirectionalRelation = $this->getBidirectionalRelation();
        $persistHook           = $this->getPersistHook();

        return $context->ignoreRelationsFor(
                function () use ($context, $children, $persistHook) {
                    return $context->ignorePersistHooksFor(function () use ($context, $children) {

                        return $this->mapper->persistAll($context, array_filter($children));

                    }, $persistHook ? [$persistHook] : []);
                },
                $bidirectionalRelation ? [$bidirectionalRelation] : []
        );
    }
814049
public function handleChildrenPersist(PersistEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof ArticleDocument) {
            return;
        }

        foreach ($document->getChildren() as $childDocument) {
            if (!$childDocument instanceof ArticlePageDocument) {
                continue;
            }

            $localizationState = $this->documentInspector->getLocalizationState($childDocument);

            if (LocalizationState::GHOST === $localizationState) {
                continue;
            }

            $changed = false;

            if ($document->getStructureType() !== $childDocument->getStructureType()) {
                $childDocument->setStructureType($document->getStructureType());
                $changed = true;
            }

            if ($document->getShadowLocale() !== $childDocument->getShadowLocale()) {
                $childDocument->setShadowLocale($document->getShadowLocale());
                $changed = true;
            }

            if ($document->isShadowLocaleEnabled() !== $childDocument->isShadowLocaleEnabled()) {
                $childDocument->setShadowLocaleEnabled($document->isShadowLocaleEnabled());
                $changed = true;
            }

            if ($changed) {
                $this->documentManager->persist(
                    $childDocument,
                    $childDocument->getLocale(),
                    [
                        'clear_missing_content' => false,
                        'auto_name' => false,
                        'auto_rename' => false,
                    ]
                );
            }
        }
    }
851608
void setBaseValues(CatalogMap<? extends CatalogType> parentMap, String name) {
        if (name == null) {
            throw new CatalogException("Null value where it shouldn't be.");
        }
        m_parentMap = parentMap;
        m_typename = name;
    }
1186380
public function handleSetParentNode(PersistEvent $event)
    {
        if (!$event->getDocument() instanceof DateShardingBehavior || $event->hasParentNode()) {
            return;
        }

        $date = $event->getDocument()->getCreated();
        if (null === $date) {
            $date = new \DateTime();
        }

        $path = $this->pathBuilder->build(['%base%', '%articles%', $date->format('Y'), $date->format('m')]);

        $event->setParentNode($this->nodeManager->createPath($path));
    }
339997
protected static function executeFields(ExecutionContext $context, ObjectType $parent, $source, $fields)
    {
        return self::executeFieldsSerially($context, $parent, $source, $fields);
    }
1033449
public function loadRelation(LoadingContext $context, ParentMapBase $map)
    {
        if (!$map->getAllParents()) {
            return;
        }

        $separateTableRelations = $this->memberMapping->getSeperateTableRelations();

        /** @var ISeparateTableRelation|null $firstRelation */
        $firstRelation = array_shift($separateTableRelations);

        if (!$firstRelation) {
            $this->memberMapping->getRelation()->load($context, $map);

            return;
        }

        $relationSelect = $firstRelation->getRelationSelectFromParentRows($map, $parentIdColumnName, $mapIdColumn);

        if ($mapIdColumn) {
            $map = $map->withPrimaryKeyColumn($mapIdColumn);
        }

        $tableAlias = $relationSelect->getTableAlias();

        foreach ($separateTableRelations as $relation) {
            $tableAlias = $relation->joinSelectToRelatedTable(
                $tableAlias,
                Join::INNER,
                $relationSelect
            );
        }

        $parentIdColumn = $relationSelect->getAliasColumnMap()[$parentIdColumnName];
        $relationSelect->setColumns(['__parent_id__' => $parentIdColumn]);
        $parentIdColumnName = '__parent_id__';

        $allRelations = $this->memberMapping->getRelationsToSubSelect();
        $lastRelation = end($allRelations);

        if ($lastRelation instanceof ISeparateToOneTableRelation) {
            /** @var ParentChildMap $map */
            $lastRelation->loadFromSelect($context, $map, $relationSelect, $tableAlias, $parentIdColumnName);
        } elseif ($lastRelation instanceof ISeparateToManyTableRelation) {
            /** @var ParentChildrenMap $map */
            $lastRelation->loadFromSelect($context, $map, $relationSelect, $tableAlias, $parentIdColumnName);
        } elseif ($lastRelation instanceof EmbeddedObjectRelation) {
            /** @var ParentChildMap $map */
            $this->loadEmbeddedObjectRelation($context, $map, $lastRelation, $relationSelect, $tableAlias, $parentIdColumnName);
        } else {
            throw InvalidArgumentException::format('Unknown relation type %s', get_class($lastRelation));
        }
    }