Set a model as the parent of another model.

@param ModelInterface $childModel  The model to become the child.
@param ModelInterface $parentModel The model to use as parent.

@return void

@throws DcGeneralRuntimeException When no condition is defined.
515409
public function setParent(ModelInterface $childModel, ModelInterface $parentModel)
    {
        $condition = $this->relationships->getChildCondition(
            $parentModel->getProviderName(),
            $childModel->getProviderName()
        );
        if (!$condition instanceof ParentChildConditionInterface) {
            throw new DcGeneralRuntimeException(
                'No condition defined from ' . $parentModel->getProviderName() . ' to ' . $childModel->getProviderName()
            );
        }

        $condition->applyTo($parentModel, $childModel);
    }
850627
public function save(Domain $model): void
    {
        if (!$model->save()) {
            throw new \RuntimeException($this->i18n->t('setrun/sys', 'Saving error'));
        }
    }
1002308
public function setParent($parent)
    {
        if (!$parent instanceof ClassDescriptor && !$parent instanceof InterfaceDescriptor && $parent !== null) {
            throw new \InvalidArgumentException('Constants can only have an interface or class as parent');
        }

        $fqsen = $parent !== null
            ? $parent->getFullyQualifiedStructuralElementName() . '::' . $this->getName()
            : $this->getName();

        $this->setFullyQualifiedStructuralElementName($fqsen);

        $this->parent = $parent;
    }
1195619
public function setDealerAdmin(ChildDealerAdmin $v = null)
    {
        if ($v === null) {
            $this->setId(NULL);
        } else {
            $this->setId($v->getId());
        }

        $this->aDealerAdmin = $v;

        // Add binding for other direction of this n:n relationship.
        // If this object has already been added to the ChildDealerAdmin object, it will not be re-added.
        if ($v !== null) {
            $v->addDealerAdminVersion($this);
        }


        return $this;
    }
252070
public function add($childModel)
    {
        if (is_array($childModel)) {
            $this->collection[] = new ModelChild($childModel);
        } elseif (is_object($childModel) && $childModel instanceof ModelChild) {
            $this->collection[] = $childModel;
        }

        return $this;
    }
1180333
public function setModel(ModelInterface $model = null): ModelReferenceInterface
    {
        $this->resolveModel();

        $this->model = $model;
        $this->id = null !== $model ? $model->getId() : null;

        return $this;
    }
862677
public function setSameParent(ModelInterface $receivingModel, ModelInterface $sourceModel, $parentTable)
    {
        if ($this->relationshipManager->isRoot($sourceModel)) {
            $this->relationshipManager->setRoot($receivingModel);

            return $this;
        }

        $this->relationshipManager->setSameParent($receivingModel, $sourceModel, $parentTable);

        return $this;
    }
898286
public function setParentConfig(CommandConfig $parentConfig)
    {
        $this->parentConfig = $parentConfig;

        if ($parentConfig->getApplicationConfig()) {
            $this->setApplicationConfig($parentConfig->getApplicationConfig());
        }
    }
483149
protected function _changeParent(Model $model, $id = null, $parentId = null) {
		$parentField = $this->_getBehaviorConfig($model, 'parent');
		if (empty($id) || ($parentField === null)) {
			return false;
		}

		$model->recursive = -1;
		$treeItem = $model->read(null, $id);
		if (empty($treeItem)) {
			return false;
		}

		$treeItem[$model->alias][$parentField] = $parentId;
		$result = (bool)$model->save($treeItem);

		return $result;
	}
492849
public function setParentIdColumnName(string $parentIdColumnName): void
    {
        $parentIdColumnName = trim($parentIdColumnName);

        if (empty($parentIdColumnName)) {
            throw new InvalidArgumentException('parentIdColumnName cannot be empty');
        }

        $this->parentIdColumnName = $parentIdColumnName;
    }
714051
private function intersectModelSetParentId(ModelInterface $intersectModel, EnvironmentInterface $environment)
    {
        $dataDefinition       = $environment->getDataDefinition();
        $parentDataDefinition = $environment->getParentDataDefinition();

        if (null === $parentDataDefinition) {
            return;
        }

        $relationships  = $dataDefinition->getModelRelationshipDefinition();
        $childCondition =
            $relationships->getChildCondition($parentDataDefinition->getName(), $dataDefinition->getName());

        $parentField = null;
        foreach ($childCondition->getSetters() as $setter) {
            if (!\array_key_exists('to_field', $setter)) {
                continue;
            }

            $parentField = $setter['to_field'];
            break;
        }

        if (null !== $parentField) {
            $intersectModel->setProperty(
                $parentField,
                ModelId::fromSerialized($environment->getInputProvider()->getParameter('pid'))
                    ->getId()
            );
        }
    }
154258
public function copyFrom($sourceModel, $destinationModel)
    {
        $this->guardProviderNames($sourceModel);
        $this->guardProviderNames($destinationModel);

        $setters = $this->getSetters();

        if (empty($setters) || !\is_array($setters)) {
            throw new DcGeneralRuntimeException(
                \sprintf(
                    'No relationship setter defined from %s to %s.',
                    $this->getSourceName(),
                    $this->getDestinationName()
                )
            );
        }

        foreach ($setters as $setter) {
            if (!$this->isValidSetter($setter)) {
                throw new DcGeneralRuntimeException(
                    \sprintf(
                        'Invalid relationship setter entry, ensure it is an array containing only "to_field" and
                    one of "from_field", "value": %s',
                        \var_export($setter, true)
                    )
                );
            }

            if (isset($setter['from_field'])) {
                $destinationModel->setProperty($setter['to_field'], $sourceModel->getProperty($setter['to_field']));

                continue;
            }

            $destinationModel->setProperty($setter['to_field'], $setter['value']);
        }
    }
1360361
public function setAncestor(ChildSkill $v = null)
    {
        if ($v === null) {
            $this->setAncestorId(NULL);
        } else {
            $this->setAncestorId($v->getId());
        }

        $this->aAncestor = $v;

        // Add binding for other direction of this n:n relationship.
        // If this object has already been added to the ChildSkill object, it will not be re-added.
        if ($v !== null) {
            $v->addLineageRelatedByAncestorId($this);
        }


        return $this;
    }
605376
public function set_parent(Fieldset $fieldset)
	{
		if ( ! empty($this->fieldset_parent))
		{
			throw new \RuntimeException('Fieldset already has a parent, belongs to "'.$this->parent()->name.'".');
		}

		$children = $fieldset->children();
		while ($child = array_shift($children))
		{
			if ($child === $this)
			{
				throw new \RuntimeException('Circular reference detected, adding a Fieldset that\'s already a child as a parent.');
			}
			$children = array_merge($child->children(), $children);
		}

		$this->fieldset_parent = $fieldset;
		$fieldset->add_child($this);
		return $this;
	}
1046893
private function parentsOf($model, &$parents)
    {
        $environment    = $this->getEnvironment();
        $dataDefinition = $environment->getDataDefinition();
        $collector      = new ModelCollector($this->getEnvironment());
        $relationships  = new RelationshipManager(
            $dataDefinition->getModelRelationshipDefinition(),
            $dataDefinition->getBasicDefinition()->getMode()
        );

        if (!$relationships->isRoot($model)) {
            $parent = $collector->searchParentOf($model);
            if (!isset($parents[$model->getProviderName()][$parent->getId()])) {
                $this->parentsOf($parent, $parents);
            }
        }

        $parents[$model->getProviderName()][$model->getId()] = 1;
    }
159351
public function set_parent(Node_Container $parent=null)
	{
		$this->parent = $parent;

		if($parent instanceof Node_Container_Document)
			$this->root = $parent;
		else
			$this->root = $parent->root();
	}
155693
public function link($childModel)
    {
        return $this->hasMany(Link::class, 'id_parent')->whereModelParent($this->config->model)->whereModelChild($childModel)->get();
    }