Передача моделей для связывания.

@param Model $modelParent    Что связываем
@param Model $modelChild     С чем связываем
@return $this
331322
public function setModels($modelParent, $modelChild)
    {
        $this->modelParent = $modelParent;
        $this->modelChild = $modelChild;

        return $this;
    }
313096
public function creatOrUpdateByParent( $parent, $metas, $config = [] ) {

		$modelClass = static::$modelClass;

		// Disable all existing metas for given type
		if( isset( $config[ 'type' ] ) && isset( $config[ 'disable' ] ) ) {

			$this->disableByType( $parent, $config[ 'type' ] );
		}

		// Create/Update given metas
		if( !empty( $metas ) && count( $metas ) > 0 ) {

			foreach( $metas as $meta ) {

				$model = new $modelClass();

				$model->name	= $meta[ 'name' ];
				$model->label	= empty( $meta[ 'label' ] ) ? $meta[ 'name' ] : $meta[ 'label' ];
				$model->value	= $meta[ 'value' ];
				$model->type	= $meta[ 'type' ];
				$model->active	= true;
				$model->icon	= !empty( $meta[ 'icon' ] ) ? $meta[ 'icon' ] : null;

				$model->modelId	= $parent->id;

				$model->valueType = empty( $meta[ 'valueType' ] ) ? $modelClass::VALUE_TYPE_TEXT : $meta[ 'valueType' ];

				if( isset( $meta[ 'id' ] ) ) {

					$model->id		= $meta[ 'id' ];
					$model->icon	= !empty( $meta[ 'icon' ] ) ? $meta[ 'icon' ] : $model->icon;

					parent::update( $model, [ 'attributes' => [ 'icon', 'name', 'value', 'active', 'type', 'valueType' ] ] );
				}
				else {

					parent::create( $model );
				}
			}
		}
	}
670530
public function createFromModel(Model $model)
    {
        $this->model = $model;
        $this->query = $this->model->newQuery();

        return $this;
    }
226775
public function setModel(Model $model)
    {
        parent::setModel($model);
        $this->setHtmlAttribute('data-value', $this->getModelValue());

        return $this;
    }
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;
    }
1282476
public function link(Model $model) {
        $this->getLinked()->flush()->append($model);

        $this->getPrimaryModel()->set($this->getPrimaryForeignKey(), $model->id());

        return $this;
    }
443855
protected function writeToModel($modelFile, $inPlaceholder = "    //")
    {
        $replaces = [];
        $searches = [];

        foreach ($this->getProperties() as $property => $content) {
            $replaces[] = $this->parsePropertyValue($content);
            $searches[] = '{{' . $property . '}}';
        } // foreach

        $methodContent = '';
        $newContent = str_replace(
            $searches,
            $replaces,
            file_get_contents(realpath(__DIR__ . '/stubs/model-content.stub'))
        );

        if ($keys = $this->getForeignKeys()) {
            $methodContent = implode("\n\n", $this->getMethodCallsForForeignKeys());
        } // if

        $newContent = str_replace(
            ["    // {{relations}}", '// {{traits}}'],
            [$methodContent, ($traits = $this->getTraits()) ? 'use ' . implode(', ', $traits) . ';' : ''],
            $newContent
        );

        $written = file_put_contents(
            $modelFile,
            str_replace(
                $inPlaceholder,
                $newContent,
                file_get_contents($modelFile)
            )
        );

        if ($written) {
            // Success of formatting is optional.
            if (DIRECTORY_SEPARATOR === '\\') {
                $exec = ".\\vendor\\bin\\phpcbf.bat {$modelFile} --standard=PSR2";
            } else {
                $exec = "vendor/bin/phpcbf {$modelFile} --standard=PSR2";
            }

            @exec($exec, $output, $return);
        } // if

        return $written;
    }
439057
public function remove($key, Model $model)
    {
        if (false === $this->isHasMany($key)) {
            return $this;
        }
        if (true === $this->isInverse($key)) {
            throw ModelException::cannotModifyInverse($this, $key);
        }
        $this->touch();
        $collection = $this->hasManyRelationships->get($key);
        $collection->remove($model);
        $this->doDirtyCheck();
        return $this;
    }
376461
public function hasMany($name, $foreignKey, $modelName = null)
    {
        $this->addAssociation('hasMany', $name, $foreignKey, $modelName);
        return $this;
    }
499786
public function deleteByParent( $parentId, $parentType ) {

		//$modelClass	= static::$modelClass;

		//return $modelClass::deleteByParent( $parentId, $parentType );

		$models	= $this->getByParent( $parentId, $parentType );

		foreach ( $models as $model ) {

			$this->delete( $model );
		}
	}
1201538
public function setParent(Step $parent = null)
    {
        if ($parent !== $this->parent) {
            $this->parent = $parent;

            if (null !== $parent) {
                $parent->addChild($this);
            }
        }

        return $this;
    }
114534
protected function applySorts(ModelQueryBuilder $builder): self
    {
        if ($this->hasSorts() === true) {
            $builder->addSorts($this->getSorts());
        }

        return $this;
    }
316114
private function addParentFilter(ConfigInterface $config, ModelInterface $parentModel)
    {
        $environment     = $this->getEnvironment();
        $definition      = $environment->getDataDefinition();
        $basicDefinition = $definition->getBasicDefinition();

        if (!$basicDefinition->getParentDataProvider()) {
            return;
        }

        if ($basicDefinition->getParentDataProvider() !== $parentModel->getProviderName()) {
            throw new \RuntimeException(
                \sprintf(
                    'Parent provider mismatch: %s vs. %s',
                    $basicDefinition->getParentDataProvider(),
                    $parentModel->getProviderName()
                )
            );
        }

        // Apply parent filtering, do this only for root elements.
        if ($parentCondition = $definition->getModelRelationshipDefinition()->getChildCondition(
            $basicDefinition->getParentDataProvider(),
            $basicDefinition->getRootDataProvider()
        )) {
            $baseFilter = $config->getFilter();
            $filter     = $parentCondition->getFilter($parentModel);

            if ($baseFilter) {
                $filter = \array_merge($baseFilter, $filter);
            }

            $config->setFilter($filter);
        }
    }
1308256
protected function applyListParentContext()
    {
        $parents = $this->getModelInformation()->list->parents;

        if (empty($parents)) {
            return $this;
        }

        if ($this->listParentRelation) {
            $contextKey = $this->listParentRelation . $this->getListParentSeparator() . $this->listParentRecordKey;
        } else {
            $contextKey = null;
        }

        $this->getListMemory()->setSubContext($contextKey);

        return $this;
    }
1172768
public function link(Model $model) {
        $this->getRelation($this->getAlias(get_class($model)))->link($model);

        return $this;
    }
1136678
protected function setForeignAttributesForCreate(Model $model)
    {
        $foreignKey = $this->getForeignKeyName();
        $parentKeyValue = $this->getParentKey();
        if (is_array($foreignKey)) { //Check for multi-columns relationship
            foreach ($foreignKey as $index => $key) {
                $model->setAttribute($key, $parentKeyValue[$index]);
            }
        } else {
            parent::setForeignAttributesForCreate($model);
        }
    }
350378
public function getParentModels($withNamespace = false)
    {
        $modelNameSpace = null;

        // first load parentModels
        if (!isset($parentModels)) {
            /** @var BaseModel $path */
            $config = $this->getDI()->get('config');
            $modelNameSpace = $config['namespaces']['models'];
            $path = $modelNameSpace . $this->getModelName();
            $parents = array();

            $currentParent = $path::$parentModel;

            while ($currentParent) :
                $parents[] = $currentParent;
                $path = $modelNameSpace . $currentParent;
                $currentParent = $path::$parentModel;
            endwhile;
            $this->parentModels = $parents;
        }

        if (count($this->parentModels) == 0) {
            return false;
        }

        // reset name space if it was not asked for
        if (!$withNamespace) {
            $modelNameSpace = null;
        }

        $parents = [];
        foreach ($this->parentModels as $parent) {
            $parents[] = $modelNameSpace . $parent;
        }

        return $parents;
    }