Update relation data.

@param array $relationsData

@return void
7156
protected function updateRelation($relationsData)
    {
        foreach ($relationsData as $name => $values) {
            if (!method_exists($this->model, $name)) {
                continue;
            }

            $relation = $this->model->$name();

            $oneToOneRelation = $relation instanceof Relations\HasOne
                || $relation instanceof Relations\MorphOne
                || $relation instanceof Relations\BelongsTo;

            $prepared = $this->prepareUpdate([$name => $values], $oneToOneRelation);

            if (empty($prepared)) {
                continue;
            }

            switch (true) {
                case $relation instanceof Relations\BelongsToMany:
                case $relation instanceof Relations\MorphToMany:
                    if (isset($prepared[$name])) {
                        $relation->sync($prepared[$name]);
                    }
                    break;
                case $relation instanceof Relations\HasOne:

                    $related = $this->model->$name;

                    // if related is empty
                    if (is_null($related)) {
                        $related = $relation->getRelated();
                        $qualifiedParentKeyName = $relation->getQualifiedParentKeyName();
                        $localKey = Arr::last(explode('.', $qualifiedParentKeyName));
                        $related->{$relation->getForeignKeyName()} = $this->model->{$localKey};
                    }

                    foreach ($prepared[$name] as $column => $value) {
                        $related->setAttribute($column, $value);
                    }

                    $related->save();
                    break;
                case $relation instanceof Relations\BelongsTo:
                case $relation instanceof Relations\MorphTo:

                    $parent = $this->model->$name;

                    // if related is empty
                    if (is_null($parent)) {
                        $parent = $relation->getRelated();
                    }

                    foreach ($prepared[$name] as $column => $value) {
                        $parent->setAttribute($column, $value);
                    }

                    $parent->save();

                    // When in creating, associate two models
                    $foreignKeyMethod = (app()->version() < '5.8.0') ? 'getForeignKey' : 'getForeignKeyName';
                    if (!$this->model->{$relation->{$foreignKeyMethod}()}) {
                        $this->model->{$relation->{$foreignKeyMethod}()} = $parent->getKey();

                        $this->model->save();
                    }

                    break;
                case $relation instanceof Relations\MorphOne:
                    $related = $this->model->$name;
                    if (is_null($related)) {
                        $related = $relation->make();
                    }
                    foreach ($prepared[$name] as $column => $value) {
                        $related->setAttribute($column, $value);
                    }
                    $related->save();
                    break;
                case $relation instanceof Relations\HasMany:
                case $relation instanceof Relations\MorphMany:

                    foreach ($prepared[$name] as $related) {
                        /** @var Relations\Relation $relation */
                        $relation = $this->model()->$name();

                        $keyName = $relation->getRelated()->getKeyName();

                        $instance = $relation->findOrNew(Arr::get($related, $keyName));

                        if ($related[static::REMOVE_FLAG_NAME] == 1) {
                            $instance->delete();

                            continue;
                        }

                        Arr::forget($related, static::REMOVE_FLAG_NAME);

                        $instance->fill($related);

                        $instance->save();
                    }

                    break;
            }
        }
    }
921098
public function updatePivotRecords()
    {
        $pivots = $this->entityMap->getPivotRelationships();

        foreach ($pivots as $pivot) {
            if (array_key_exists($pivot, $this->relationships)) {
                $this->updatePivotRelation($pivot);
            }
        }
    }
361959
protected void processRelationships(final ParserData parserData) {
        // Process the level relationships
        for (final Map.Entry<String, List<Relationship>> entry : parserData.getLevelRelationships().entrySet()) {
            final String levelId = entry.getKey();
            final Level level = parserData.getLevels().get(levelId);

            assert level != null;

            for (final Relationship relationship : entry.getValue()) {
                processRelationship(parserData, level, relationship);
            }
        }

        // Process the topic relationships
        for (final Map.Entry<String, List<Relationship>> entry : parserData.getTopicRelationships().entrySet()) {
            final String topicId = entry.getKey();
            final SpecTopic specTopic = parserData.getSpecTopics().get(topicId);

            assert specTopic != null;

            for (final Relationship relationship : entry.getValue()) {
                processRelationship(parserData, specTopic, relationship);
            }
        }
    }
106495
public function update($featureData)
    {
        /** @var Feature $feature */
        $feature                       = $this->create($featureData);
        $data                          = $this->cleanFeatureData($feature->toArray());
        $connection                    = $this->getConnection();
        $data[ $this->getGeomField() ] = $this->transformEwkt($data[ $this->getGeomField() ]);
        unset($data[ $this->getUniqueId() ]);

        $event             = array(
            'item'    => &$data,
            'feature' => $feature
        );
        $this->allowUpdate = true;

        if (isset($this->events[ static::EVENT_ON_BEFORE_UPDATE ])) {
            $this->secureEval($this->events[ static::EVENT_ON_BEFORE_UPDATE ], $event);
        }
        if (empty($data)) {
            throw new \Exception("Feature can't be updated without criteria");
        }

        $tableName = $this->getTableName();
        $keys = array_keys($data);
        foreach($data as $key => $value){
            $quotedData[$connection->quoteIdentifier($key)] = $value;
        }



        if ($this->allowUpdate) {
            $connection->update($tableName, $quotedData, array($this->getUniqueId() => $feature->getId()));
        }

        if (isset($this->events[ self::EVENT_ON_AFTER_UPDATE ])) {
            $this->secureEval($this->events[ self::EVENT_ON_AFTER_UPDATE ], $event);
        }
        return $feature;
    }
812663
public function updateRelations($entity) {
        $mapper = MapperBuilder::buildFromMapping($this->mapping, get_class($entity));
        foreach ($mapper->getRelations() as $relation) {
            if ($relation->getCardinality() == Relation::$manyToMany) {
                // delete previous relations
                $queryDeletePrevious = $this->buildDeleteRelationQuery($relation, $entity);
                $this->conn->executeNonQuery($queryDeletePrevious);

                // insert new relations
                $queryRel = $this->buildRelationQuery($entity);
                foreach (explode(";", $queryRel) as $q) {
                    if (strlen($q) > 5)
                        $this->conn->executeInsert($q);
                }
            }
            if ($relation->getCardinality() == Relation::$oneToMany) {
                $relMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());
                $m = "get" . $relation->getName();
                $setid = "set" . $relMapper->getNameForColumn($relation->getForeignColumn());

                // save actual relations
                foreach ($entity->$m() as $relEntity) {
                    $relEntity->$setid($entity->getId());
                    $this->save($relEntity);
                }

                //  delete old relations.
                // TODO: delete old relations
            }
        }
    }
580804
public void setRelationalDatabases(java.util.Collection<RelationalDatabase> relationalDatabases) {
        if (relationalDatabases == null) {
            this.relationalDatabases = null;
            return;
        }

        this.relationalDatabases = new java.util.ArrayList<RelationalDatabase>(relationalDatabases);
    }
1063101
protected function assignRelations($relations)
    {
        foreach ($relations as $relation) {
            if (!$relation instanceof RelationInterface) {
                throw new ModelException(sprintf('Relation must be an instance of RelationInterface, got "%s"', $this->getType($relation)));
            }

            foreach (array_keys($relation->keys()) as $field) {
                $this->assertField($field);
            }

            $this->relations[$relation->name()] = $relation;
        }
    }
302951
public function addRelation($name) {
    if (!$this->hasValue($name)) {
      $this->relationStates[$name] = self::RELATION_STATE_UNINITIALIZED;
      $this->setValueInternal($name, null);
    }
  }
779129
public function setRelation(Relationship $relation, $debug = false)
    {
        // Set the relation object.
        $this->relation = $relation;

        // Replace the attributes with those brought from the given relation.
        $this->attributes = $relation->getProperties();
        //$this->setAttribute($this->primaryKey, $relation->getId());

        // Set the start and end nodes.
        $this->start = $relation->getStartNode();
        $this->end   = $relation->getEndNode();

        // Instantiate and fill out the related model.
        $relatedNode = ($this->isDirectionOut()) ? $this->end : $this->start;
        $attributes = array_merge(['id' => $relatedNode->getId()], $relatedNode->getProperties());

        // This is an existing relationship.
        $exists = true;
        $this->related = $this->related->newFromBuilder($attributes, $exists);
        $this->related->setConnection($this->related->getConnection());
    }
210716
public function updateData(array $data) {
        foreach($data as $name => $value) {
            $this->data[$name] = $value;
        }
    }
778852
public function update(array $data, array $identifiers)
    {
        $this->getConnection()->update(
            $this->getTableName(),
            $data,
            $identifiers
        );
    }
411743
public function setNodeData(NodeData $nodeData): void
    {
        $this->nodeData = $nodeData;
        $this->nodeDataIsMatchingContext = null;
    }
601428
public function init(array $frontendData): void
    {
        $this->_frontendData = Hash::merge(
            $this->_frontendData, $frontendData
        );
        $this->_includeAppController();
        $this->_includeComponents();
    }
158848
private function addRelations(Repository $repo, MutableBag $relationQueue, Bag $importDatum, MutableBag $relationFields)
    {
        $classMeta = $repo->getClassMetadata();
        foreach ($relationFields as $fieldName) {
            $relationName = $classMeta->getBoltName() . '/' . $importDatum->get('slug');

            $existing = (array) $relationQueue->get($relationName);
            $relatedEntities = $importDatum->get($fieldName);

            if ($relatedEntities) {
                $relationQueue->set($relationName, array_merge($relatedEntities->toArray(), $existing));
            }
        }
    }
1058304
public function setRelated(array $data, $delete_old = true)
    {
        if (empty($data['form']) && empty($data['related'])) {
            return false;
        }

        if ($delete_old) {
            $this->product_relation->delete($data['product_id']);
        }

        if (!empty($data['related'])) {
            foreach ((array) $data['related'] as $related_product_id) {
                $this->product_relation->add($related_product_id, $data['product_id']);
            }
            return true;
        }

        return false;
    }
280856
public function _update_original($original = null)
	{
		$original = is_null($original) ? $this->_data : $original;
		$this->_original = array_merge($this->_original, $original);

		$this->_update_original_relations();
	}
294937
protected function fixDefaultRelations(array & $relations)
    {
        foreach ($relations as $key => $relation) {
            if ('role_adldap_by_role_id' === $relation && !class_exists(LDAP::class)) {
                unset($relations[$key]);
            }
        }
    }