Get relation by model name

@param  string $modelName

@return RowInterface
@throws RelationNotFoundException
@throws TableNotFoundException
194349
public function getRelation($modelName): ?RowInterface
    {
        $relations = $this->getRelations($modelName);
        return empty($relations) ? null : current($relations);
    }
1006192
public function findByParam($modelName, $param)
    {
        /**
         * @var ModelStorageDecorator $storedModel
         */
        foreach ($this->storage as $key => $storedModel) {
            if ($modelName != get_class($storedModel)) {
                continue;
            }

            if ($this->containsParam($storedModel, $param)) {
                return $storedModel->getModel();
            }
        }

        return null;
    }
768587
public function getModelPersister($modelName)
    {
        if (!isset($this->persisters[$modelName])) {
            $class = $this->manager->getClassMetadata($modelName);

            $this->persisters[$modelName] = new ModelPersister($this->manager, $this, $class);
        }

        return $this->persisters[$modelName];
    }
1082482
protected function getModelName($tableName)
    {
        $modelName = ResourceMapper::pluckFirst($tableName, 'table-name', 'model-name');

        return $modelName ?: $this->makeModelName($tableName);
    }
433567
public function results($modelName)
    {
        $dataTable = app('admin_datatable');

        //get the sort options and filters
        $page        = $this->request->input('page', 1);
        $sortOptions = $this->request->input('sortOptions', array());
        $filters     = $this->request->input('filters', array());

        //return the rows
        return response()->json($dataTable->getRows(app('db'), $filters, $page, $sortOptions));
    }
814222
public function getTableName($modelName)
    {
        if (! isset($this->_unionModels[$modelName])) {
            return null;
        }

        $model = $this->_unionModels[$modelName];

        if ($model instanceof \MUtil_Model_TableModel) {
            return $model->getTableName();
        }
    }
1331648
public function setModelName($modelName)
    {
        if (0 === strpos($modelName, '\\')) {
            $this->modelName = substr($modelName, 1);
        } else {
            $this->modelName = $modelName;
        }
        if ($this->modelName && !$this->modelTableMapName) {
            $this->modelTableMapName = constant($this->modelName . '::TABLE_MAP');
        }
        if (!$this->tableMap && $this->modelName) {
            $this->tableMap = Propel::getServiceContainer()->getDatabaseMap($this->getDbName())->getTableByPhpName($this->modelName);
        }

        return $this;
    }
136828
public function get(string $name): RelationshipInterface
    {
        if (!$this->has($name)) {
            throw new \InvalidArgumentException('Relationship ' . $name . ' not available');
        }

        return $this->collection[$name];
    }
628502
protected static function getModelsForRelation($model, $relationKey)
    {
        if (!method_exists($model, $relationKey)) {
            throw new Exception(
                    'Relation "' . $relationKey . '" does not exist in model',
                    static::ERROR_SCOPE | static::ERROR_UNKNOWN_ID,
                    BaseResponse::HTTP_INTERNAL_SERVER_ERROR
                );
        }
        $relationModels = $model->{$relationKey};
        if (is_null($relationModels)) {
            return null;
        }

        if (! $relationModels instanceof Collection) {
            return [ $relationModels ];
        }

        return $relationModels;
    }
59499
public function getRepository($modelName, $collection = null)
    {
        return $this->repositoryFactory->getRepository($this, $modelName, $collection);
    }
45705
protected function getModelTpl($modelClassName, $tableName)
    {
        $modelTpl = str_replace(CodeTpl::CLASS_NAME_TAG, $modelClassName, CodeTpl::MODEL_TPL);

        /**
 * @var \PDOStatement $statement 
*/
        $statement = Connection::component()->read_conn->prepare('desc ' . $tableName);
        if ($result = $statement->execute()) {
            $fields = $statement->fetchAll();

            if (!$fields) {
                throw new ParamException(ErrorMsg::INVALID_PARAM);
            }

            //Assemble Attributes & Labels
            $primaryKeyAttr = '';
            $attributes = '';

            $primaryKeyLabel = '';
            $labels = '';

            $primaryKey = '';

            $primaryKeyComment = '';
            $propertyComments = '';

            $setter = '';
            $getter = '';

            foreach ($fields as $field) {
                $attrName = $field['Field'];
                $defaultValue = $this->formatValue($field['Default'], $field['Type']);
                $label = $this->formatLabel($attrName);
                $commentType = $this->getCommentType($field['Type']);
                $camelAttrName = $this->formatAttr($attrName);

                //Setter
                $setter .= <<<EOF
    public function set{$camelAttrName}(\$value)
    {
        \$this->{$attrName} = \$value;
        return \$this;
    }
EOF;
                $setter .= (str_repeat(PHP_EOL, 2));

                //Getter
                $getter .= <<<EOF
    public function get{$camelAttrName}()
    {
        return \$this->{$attrName};
    }
EOF;
                $getter .= (str_repeat(PHP_EOL, 2));

                if ($field['Key'] == 'PRI') {
                    //Primary Key
                    $primaryKey = $attrName;

                    //Primary Key Attribute
                    $primaryKeyAttr = <<<EOF
    '{$attrName}' => {$defaultValue},
EOF;
                    $primaryKeyAttr .= PHP_EOL;

                    //Primary Key Label
                    $primaryKeyLabel = <<<EOF
    '{$attrName}' => '{$label}',
EOF;
                    $primaryKeyLabel .= PHP_EOL;

                    //Primary Key Comment
                    $primaryKeyComment = <<<EOF
 * @property {$commentType} \${$attrName}
EOF;
                    $primaryKeyComment .= PHP_EOL;
                } else {
                    //Attributes
                    $attributes .= <<<EOF
        '{$attrName}' => {$defaultValue},
EOF;
                    $attributes .= PHP_EOL;

                    //Labels
                    $labels .= <<<EOF
        '{$attrName}' => '{$label}',
EOF;
                    $labels .= PHP_EOL;

                    //Property Comment
                    $propertyComments .= <<<EOF
 * @property {$commentType} \${$attrName}
EOF;
                    $propertyComments .= PHP_EOL;
                }
            }
            $modelTpl = str_replace(CodeTpl::ATTRIBUTES_TAG, rtrim($primaryKeyAttr . $attributes, PHP_EOL), $modelTpl);
            $modelTpl = str_replace(CodeTpl::LABELS_TAG, rtrim($primaryKeyLabel . $labels, PHP_EOL), $modelTpl);
            $modelTpl = str_replace(
                CodeTpl::PROPERTY_COMMENTS_TAG,
                rtrim($primaryKeyComment . $propertyComments, PHP_EOL),
                $modelTpl
            );
            $modelTpl = str_replace(CodeTpl::PRIMARY_KEY_TAG, $primaryKey, $modelTpl);
            $modelTpl = str_replace(CodeTpl::SETTER, $setter, $modelTpl);
            $modelTpl = str_replace(CodeTpl::GETTER, rtrim($getter, PHP_EOL), $modelTpl);
        }

        return str_replace(CodeTpl::TABLE_NAME_TAG, $tableName, $modelTpl);
    }
658742
public static function createRow($modelName, $data): RowInterface
    {
        $tableClass = self::getModelClass($modelName);

        /* @var Table $tableClass name */
        return $tableClass::getInstance()::create($data);
    }
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;
    }
983670
public function find($id)
    {
        if (!$this->modelClass) {
            throw new ModelNotFoundException('setModelClass');
        }

        return $this->manager->getRepository($this->modelClass)->find($id);
    }
564682
protected function _getSchemaCache($modelName = null) {
		if (empty($modelName)) {
			return null;
		}

		$modelName = (string)$modelName;
		if (!isset($this->_schemaCache[$modelName])) {
			return null;
		}

		return $this->_schemaCache[$modelName];
	}
14468
public function getRelation($name) {
        // We want to run a relationship query without any constrains so that we will
        // not have to remove these where clauses manually which gets really hacky
        // and error prone. We don't want constraints because we add eager ones.
        $relation = Relation::noConstraints(function () use ($name) {
            try {
                return $this->getModel()->{$name}();
            } catch (\Exception $e) {
                throw $e;//RelationNotFoundException::make($this->getModel(), $name);
            }
        });

        $nested = $this->relationsNestedUnder($name);

        // If there are nested relationships set on the query, we will put those onto
        // the query instances so that they can be handled after this relationship
        // is loaded. In this way they will all trickle down as they are loaded.
        if (count($nested) > 0) {
            $relation->getQuery()->with($nested);
        }

        return $relation;
    }
1127845
public function getTable($tableName)
    {
        if (is_array($tableName)) {
            list($tableName, $entitySuffix) = $tableName;
        } else {
            $entitySuffix = null;
        }

        if ($entitySuffix !== null) {
            $tableName .= '_' . $entitySuffix;
        }

        if (!isset($this->_tables[$tableName])) {
            $this->_tables[$tableName] = $this->_resources->getTableName(
                $tableName,
                ResourceConnection::DEFAULT_CONNECTION
            );
        }

        return $this->_tables[$tableName];
    }