获取一个model
@param $model
@param Child $parent
@return mixed|null
@throws SwooleException
548870
public function model($model, Child $parent)
    {
        if (empty($model)) {
            return null;
        }
        if($parent->root == null){
            $parent->root = $parent;
        }
        $root = $parent->root;
        if ($root->hasChild($model)) {
            return AOP::getAOP($root->getChild($model));
        }
        $model_instance = $this->_model_factory->getModel($model);
        $model_instance->root = $root;
        $root->addChild($model_instance);
        $model_instance->initialization($parent->getContext());
        return AOP::getAOP($model_instance);
    }
32850
public static function hydrateRecursive(Model $model, array $items, Relation $parentRelation = null)
    {
        $instance = $model;

        $items = array_map(function ($item) use ($instance, $parentRelation) {
            // Convert all null relations into empty arrays
            $item = $item ?: [];
            
            return static::newFromBuilderRecursive($instance, $item, $parentRelation);
        }, $items);

        return $instance->newCollection($items);
    }
734642
public function getLink($childModel)
    {
        return $this->belongsToMany($childModel, 'link', 'id_parent', 'id_child')
            ->whereModelParent($this->config->getModelName())->whereModelChild($childModel);
    }
730257
public function getOnlineChildren(Node $parent, $lang = null)
    {
        return $this->getOnlineChildrenQueryBuilder($parent, $lang)
            ->getQuery()->getResult();
    }
80259
public function linkQuery($childModel)
    {
        return $this->hasMany(Link::class, 'id_parent')->whereModelParent($this->config->model)->whereModelChild($childModel);
    }
40895
public function actionCreate($parent = null)
    {
        $model = new Area();
        if (!is_null($parent)) {
            $parent = Area::findOne(['id' => $parent]);
            if ($parent) {
                $model->parent = $parent->id;
                $model->parent_name = $parent->name;
            }
        }
        if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ActiveForm::validate($model);
        }
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            Yii::$app->getSession()->setFlash('success', Yii::t('system','Create success.'));
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }
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 );
		}
	}
1003427
public function getModel($old_model)
    {
        $model = str_replace('/', '\\', $old_model);
        if (!array_key_exists($old_model, $this->pool)) {
            $this->pool[$old_model] = new \SplStack();;
        }
        if (!$this->pool[$old_model]->isEmpty()) {
            $model_instance = $this->pool[$old_model]->shift();
            $model_instance->reUse();
            return $model_instance;
        }
        if (class_exists($model)) {
            $model_instance = new $model;
            if ($model_instance instanceof Model) {
                $model_instance->core_name = $old_model;
                $this->addNewCount($old_model);
                return $model_instance;
            }
        }

        $class_name = "app\\Models\\$model";

        if (class_exists($class_name)) {
            $model_instance = new $class_name;
            $model_instance->core_name = $old_model;
            $this->addNewCount($old_model);
        } else {
            $class_name = "Server\\Models\\$model";
            if (class_exists($class_name)) {
                $model_instance = new $class_name;
                $model_instance->core_name = $old_model;
                $this->addNewCount($old_model);
            } else {
                throw new SwooleException("class $model is not exist");
            }
        }
        return $model_instance;
    }
1199157
public function getJointParent($model, $includeSelf = false)
    {
        if ( is_numeric($model) ) {
            $model = call_user_func("$this->ownerClassName::findOne", $model);
        }
        if ( $this->owner->{$this->parentIdField} == $model->{$this->parentIdField} ) {
            return $this->getParent();
        }
        $ownerParents = $this->owner->getParents($includeSelf)->all();
        $modelParents = $model->getParents($includeSelf)->all();
        $jointParent = false;
        foreach ( $ownerParents as $idx => $parent ) {
            if ( isset($modelParents[$idx]) && $parent->{$this->primaryKey} == $modelParents[$idx]->{$this->primaryKey} ) {
                $jointParent = $parent;
            } else {
                break;
            }
        }
        return $jointParent;
    }
925674
public function getParent()
	{
		if ( ! $this->hasParent()) {
			return null;
		}
		$parents = $this->getAncestors(1);
		if ( ! isset($parents[0])) {
			$dump = static::dump($this);
			throw new Exception\InvalidStructure("Parent node was not found for {$dump} but must exist");
		}
		$parent = $parents[0];
		
		return $parent;
	}
1081153
protected function renderModel(ModelInterface $model, EnvironmentInterface $environment)
    {
        $event = new ParentViewChildRecordEvent($environment, $model);
        $environment->getEventDispatcher()->dispatch($event::NAME, $event);

        if (null !== $event->getHtml()) {
            $information = [
                [
                    'colspan' => 1,
                    'class'   => 'tl_file_list col_1',
                    'content' => $event->getHtml()
                ]
            ];
            $model->setMeta($model::LABEL_VALUE, $information);
            return;
        }

        parent::renderModel($model, $environment);
    }
354296
public function save(Storable $model, AbstractModel $parent = null)
    {
        $response = $this->request(
            $this->buildUrl($model, $parent), $model->getId() > 0 ? 'PUT' : 'POST', $this->mapper->mapToStorage($model)
        );

        return $this->mapper->mapFromStorage($response);
    }
1241230
protected function getDefaultFor(Model $parent)
    {
        if (! $this->withDefault) {
            return;
        }

        $instance = $this->newRelatedInstanceFor($parent);

        if (is_callable($this->withDefault)) {
            return call_user_func($this->withDefault, $instance, $parent) ?: $instance;
        }

        if (is_array($this->withDefault)) {
            $instance->forceFill($this->withDefault);
        }

        return $instance;
    }
74244
public function findRootParentRecursively(string $parentProperty, string $table, Model $instance, bool $returnInstanceIfNoParent = true)
    {
        if (!$instance || !$instance->{$parentProperty}
            || null === ($parentInstance = $this->findModelInstanceByPk($table, $instance->{$parentProperty}))) {
            return $returnInstanceIfNoParent ? $instance : null;
        }

        return $this->findRootParentRecursively($parentProperty, $table, $parentInstance);
    }
919865
public function setModel(Model $model)
    {
        if (strpos($this->originalName, '.') !== false) {
            $parts = explode('.', $this->originalName);
            $name = array_pop($parts);

            while ($parts) {
                $part = array_shift($parts);
                $relation = $model->getAttribute($part);

                if ($relation instanceof Model) {
                    $model = $relation;
                    $this->setName($name);
                }
            }
        }

        return parent::setModel($model);
    }
542890
public function getParentClass()
    {
        $parentClass = $this->getBehaviorContent('parentClass');
        return null === $parentClass ? ($this->getTable()->getBaseQueryClass() != "" ? $this->getTable()->getBaseQueryClass() : 'ModelCriteria') : $parentClass;
    }
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()
            );
        }
    }