Set relationship

@param string               $name
@param AbstractRelationship $relationship
514823
public function setRelationship(string $name, AbstractRelationship $relationship)
    {
        if (isset($this->relationships[$name])) {
            throw new RelationshipOverrideException($this, $name);
        }

        $this->relationships[$name] = $relationship;
    }
40336
public function insertRelationship($parent, $related, $relationship, $bindings = []) {
        $cypher = $this->grammar->compileEdge($this, $parent, $related, $relationship, $bindings);
        return $this->connection->insert($cypher, $bindings);
    }
747031
public function removeRelationship(TermRelationships $relationship)
    {
        if ($this->relationships->contains($relationship)) {
            $this->relationships->remove($relationship);
        }

        return $this;
    }
911862
public function addRelationshipObject($key, RelationshipObject $relationshipObject, array $options=[]) {
		if ($relationshipObject->hasResource($this)) {
			throw new DuplicateException('can not add relation to self');
		}
		
		if ($this->relationships === null) {
			$this->setRelationshipsObject(new RelationshipsObject());
		}
		
		$this->validator->claimUsedFields([$key], Validator::OBJECT_CONTAINER_RELATIONSHIPS, $options);
		
		$this->relationships->addRelationshipObject($key, $relationshipObject);
	}
1270220
public function set($key, $value)
    {
        if (! $value instanceof RelationInterface) {
            throw new InvalidArgumentException(
                "Only RelationInterface objects can be putted in a ".
                "RelationsMap."
            );
        }
        return parent::set($key, $value);
    }
1084922
protected function setSingleRelation($relationName, $value)
    {
        /** @var BaseActiveRecord $owner */
        $owner = $this->owner;
        /** @var ActiveQuery $relation */
        $relation = $owner->getRelation($relationName);
        if (!($value instanceof $relation->modelClass)) {
            $value = $this->processModelAsArray($value, $relation, $relationName);
        }
        $this->_newRelationValue[$relationName] = $value;
        $owner->populateRelation($relationName, $value);
    }
848778
protected function processRelationQuery($relation, $name, $value)
    {
        if (!$this->hasRelation($relation)) {
            return;
        }

        $this->reqJoin($relation);

        list($name, $op) = $this->parseNameAndOp($name);

        /** @var BaseModelV2 $related */
        $related = $this->$relation();
        if (!$related->hasColumn($name)) {
            return;
        }

        $this->queryByOp($related->getTable() . '.' . $name, $op, $value);
    }
515147
public function setRelation($relation, $value)
    {
        $this->checkInitRelations();
        $this->relations[$relation] = $value;

        return $this;
    }
1307534
public function setRelations($contentKey, $className)
    {
        if (!isset($this->contenttypes[$contentKey]['relations'])) {
            return;
        }
        foreach ($this->contenttypes[$contentKey]['relations'] as $key => $data) {
            if (isset($data['alias'])) {
                $relationKey = $data['alias'];
            } else {
                $relationKey = $key;
            }

            $mapping = [
                'fieldname' => $relationKey,
                'type'      => 'null',
                'fieldtype' => $this->typemap['relation'],
                'entity'    => $this->resolveClassName($relationKey),
                'target'    => $this->schemaManager->getTableName('relations'),
            ];

            $this->metadata[$className]['fields'][$relationKey] = $mapping;
            $this->metadata[$className]['fields'][$relationKey]['data'] = $data;
        }
    }
446890
protected function setPlatformRelationship($relationship)
    {
        if (null !== $relationship) {
            $this->writeAttribute(
                $relationship,
                'platform',
                'relationship',
                $this->validator,
                'validatePlatformRelationship',
                $this->exception,
                'Provided relationship is not a valid value.'
            );
        }

        return $this;
    }
928754
private void setRelationToEntity(Object entity, Object relationEntity, Relation relation)
    {
        if (relation.getTargetEntity().isAssignableFrom(getEntity(relationEntity).getClass()))
        {

            if (relation.isUnary())
            {
                PropertyAccessorHelper.set(entity, relation.getProperty(), getEntity(relationEntity));
            }
            else
            {
                Object associationObject = PropertyAccessorHelper.getObject(entity, relation.getProperty());
                if (associationObject == null || ProxyHelper.isProxyOrCollection(associationObject))
                {
                    associationObject = PropertyAccessorHelper.getCollectionInstance(relation.getProperty());
                    PropertyAccessorHelper.set(entity, relation.getProperty(), associationObject);
                }

                ((Collection) associationObject).add(getEntity(relationEntity));
            }
        }
    }
1080589
public function setRelation($relation, $relationColumn = null)
    {
        $this->relation = $relation;
        $this->relationColumn = $relationColumn;

        return $this;
    }
302951
public function addRelation($name) {
    if (!$this->hasValue($name)) {
      $this->relationStates[$name] = self::RELATION_STATE_UNINITIALIZED;
      $this->setValueInternal($name, null);
    }
  }
1267344
protected function recordFetchedRelationship(RelationshipResource $relationship)
    {
        $this->fetchedRelationships[] = $this->resource['type'] .
            '.' . $relationship->getName() .
            '.' . $relationship->getType();
    }
1218751
public function setRelationship($relationship)
    {
        $allowedValues = $this->getRelationshipAllowableValues();
        if (!is_null($relationship) && !in_array($relationship, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'relationship', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['relationship'] = $relationship;

        return $this;
    }
705763
public static function setRelation($modelOne, $keyOne, $modelTwo, $keyTwo): void
    {
        $relations = [$modelOne => $keyOne, $modelTwo => $keyTwo];
        self::setRelations($modelOne, $modelTwo, $relations);
    }
28501
public function setRelated($value)
    {
        $this->loadData(true);

        if (is_null($value)) {
            $value = [];
        }

        if (!is_array($value)) {
            throw new RelationException("HasMany relation can only be set with array of entities");
        }

        //Do not add items twice
        $matched = [];
        foreach ($value as $index => $record) {
            if (is_null($record)) {
                unset($value[$index]);
                continue;
            }

            $this->assertValid($record);
            if (!empty($instance = $this->matchOne($record))) {
                $matched[] = $instance;
                unset($value[$index]);
            }
        }

        //Unlink records
        foreach (array_diff($this->instances, $matched) as $record) {
            $this->unlink($record);
        }

        //Add new record
        foreach ($value as $record) {
            $this->link($record);
        }
    }