show relations of model

@param Model $model
@return void
351080
protected function showRelatoins(Model $model)
    {
        $name = $this->manager->getClassName($model);

        $this->title("Relations of Model {$name}: ");

        $relations = $this->manager->getRelations($model);
        $tbody = [];

        foreach ($relations as $relation) {
            $relationName = $this->manager->getClassName($relation);
            $related = $relation->getRelated() ?:null;

            $tbody[] = [
                $this->paintString($relationName, 'brown'),
                $related ? $this->manager->getClassName($related) : '',
            ];
        }

        $this->table(['relation', 'model'], $tbody);
    }
844741
public function creating(Model $model)
    {
        if (! $model->created_by) {
            $model->created_by = $this->getAuthenticatedUserId();
        }

        if (! $model->updated_by) {
            $model->updated_by = $this->getAuthenticatedUserId();
        }
    }
1296306
public function associate($model)
    {
        $foreignKey = $this->foreignKey;
        $pk         = $model->getPk();

        $this->parent->setAttr($foreignKey, $model->$pk);
        $this->parent->save();

        return $this->parent->setRelation($this->relation, $model);
    }
1122662
public function delete($model)
    {
        $this->db->connect()
            ->deleteFrom($this->table)
            ->where($this->key . ' = ?')
            ->execute([$model->{$this->key}]);
        $model->{$this->key} = null;
    }
662374
private function buildRelationshipAttributes($model)
    {
        $result = [];

        foreach ($model->getSearchRelationships() as $method) {
            if (!method_exists($model, $method)) {
                continue;
            }

            $relation = self::getRelation($model->$method());
            $this->relationships[$method] = $relation;

            self::buildCastedAttributes($relation['model'], $result, $method);
            self::buildSearchAttributes($relation['model'], $result, $method);
        }

        return $result;
    }
1073187
protected function loadRelationsAttributesRecursive(Model $model)
    {
        $attributes = $model->getAttributes();

        foreach ($attributes as $key => $value) {
            if (method_exists($model, $key)) {
                $reflection_method = new ReflectionMethod($model, $key);

                if ($reflection_method->class != "Illuminate\Database\Eloquent\Model") {
                    $relation = $model->$key();

                    if ($relation instanceof Relation) {

                        // Get the relation models/model if value is not null
                        if ($value === null) {
                            $models = null;
                        } else {

                          // Check if the relation field is single model or collections
                            if (!$multiLevelRelation = $this->isMultiLevelArray($value)) {
                                $value = [$value];
                            }

                            $models = $this->hydrateRecursive($relation->getModel(), $value, $relation);

                            if (!$multiLevelRelation) {
                                $models = $models->first();
                            }
                        }

                        // Unset attribute before setting relation
                        unset($model[$key]);

                        // Set the relation value
                        $model->setRelation($key, $models);
                    }
                }
            }
        }
    }
582715
public function getRelationships($model): iterable
    {
        assert($model instanceof ModelInterface);

        foreach ($this->getRelationshipsMapping() as $jsonRelName => [$modelRelName, $belongsToFkName, $reverseType]) {
            // if model has relationship data then use it
            if ($this->hasProperty($model, $modelRelName) === true) {
                yield $jsonRelName => $this->createRelationshipRepresentationFromData(
                    $model,
                    $modelRelName,
                    $jsonRelName
                );
                continue;
            }

            // if relationship is `belongs-to` and has that ID we can add relationship as identifier
            if ($belongsToFkName !== null && $this->hasProperty($model, $belongsToFkName) === true) {
                $reverseIndex = $model->{$belongsToFkName};
                $identifier   = $reverseIndex === null ?
                    null : new Identifier((string)$reverseIndex, $reverseType, false, null);

                yield $jsonRelName => [
                    static::RELATIONSHIP_DATA       => $identifier,
                    static::RELATIONSHIP_LINKS_SELF => $this->isAddSelfLinkInRelationshipWithData($jsonRelName),
                ];
                continue;
            }

            // if we are here it's nothing left but show relationship as a link
            yield $jsonRelName => [static::RELATIONSHIP_LINKS_SELF => true];
        }
    }
579147
public function deleting(Model $model)
    {
        $model->deleted_by = $this->guard->check() ? $this->guard->user()->getId() : null;
    }
1208635
public function relations()
    {
        $email = Yii::app()->getModule('email');
        if (!empty($email->modelMap[get_class($this)]['relations']))
            return $email->modelMap[get_class($this)]['relations'];
        return parent::relations();
    }
295574
public function cleanup(Model $model) {
        if ($model->id) {
            $this->resetCache($model, $model->id);
        }

        foreach ($this->_cached as $key => $value) {
            $this->deleteCache($model, $key);
        }
    }
828375
public function link(Model $model)
    {
        if ( ! $this->routePrefix || ! $this->isPermitted) {
            return false;
        }

        return route($this->routePrefix . static::ROUTE_POSTFIX, [ $model->getKey() ]);
    }
479166
public function afterDelete(Model &$model)
    {
        /** @var \T4\Orm\Model $class */
        $class = get_class($model);
        $tableName = $class::getTableName();
        /** @var \T4\Dbal\Connection $connection */
        $connection = $class::getDbConnection();

        $query = (new Query())
            ->delete()
            ->table($tableName)
            ->where('__lft>:lft AND __rgt<:rgt')
            ->params([':lft' => $model->__lft, ':rgt' => $model->__rgt]);
        $connection->execute($query);

        $this->removeFromTreeByLftRgt($connection, $tableName, $model->__lft, $model->__rgt);

        $model->__lft = 0;
        $model->__rgt = 0;
        $model->__lvl = 0;
        $model->__prt = 0;
    }
556735
public function setModel(Model $model)
    {
        parent::setModel($model);

        if ($model->exists) {
            $this->setInstance($model);
            $this->loadRelationValues();
        }
    }
1056523
public function setRelation(Row $row): void
    {
        $modelName = $row->getTable()->getModel();
        $this->relations[$modelName] = [$row];
    }
744701
protected function getNestedRelation(Model $model, $relationArray)
    {
        $relation = null;
        foreach ($relationArray as $relation) {
            /** @var Relation $relation */
            $relation = $model->newQuery()->getRelation($relation);
            if ($relation) {
                $model = $relation->getRelated();
            }
        }

        return $relation;
    }
308601
private function isRelationship($model, $conditions)
    {
        /**
         * A valid relationship must:
         * - Be a method
         * - Not appear in the 'except' list
         * - Appear in the 'only' list (if used)
         * - Extend Illuminate\Database\Eloquent\Relations\Relation
         */
        return (
            method_exists($this, $model) &&
            $this->filterRelationshipByConditions($model, $conditions) &&
            is_subclass_of($this->{Str::camel($model)}(), 'Illuminate\Database\Eloquent\Relations\Relation')
        );
    }
938315
protected function properties(Model $model)
    {
        // Process property annotations
        $annotations = '';

        foreach ($model->getProperties() as $name => $hint) {
            $annotations .= $this->class->annotation('property', "$hint \$$name");
        }

        if ($model->hasRelations()) {
            // Add separation between model properties and model relations
            $annotations .= "\n * ";
        }

        foreach ($model->getRelations() as $name => $relation) {
            // TODO: Handle collisions, perhaps rename the relation.
            if ($model->hasProperty($name)) {
                continue;
            }
            $annotations .= $this->class->annotation('property', $relation->hint()." \$$name");
        }

        return $annotations;
    }