Return a related model object.

@return \Titon\Model\Model
18976
public function getRelatedModel() {
        if ($model = $this->_relatedModel) {
            return $model;
        }

        $class = $this->getRelatedClass();

        $this->setRelatedModel(new $class());

        return $this->_relatedModel;
    }
1231655
public function roles() : BelongsToMany
    {
        $pivotTable = config('lia.database.role_users_table');

        $relatedModel = config('lia.database.roles_model');

        return $this->belongsToMany($relatedModel, $pivotTable, 'user_id', 'role_id');
    }
1303758
public function getContent()
    {
        return strtr($this->getRelationStubContent(), [
            '{{name}}'         => $this->name,
            '{{relatedTable}}' => $this->relatedModel->getTable(),
            '{{relatedModel}}' => $this->relatedModel->getClass(),
            '{{foreignKey}}'   => $this->foreignKey,
        ]);
    }
237126
public function getModel()
    {

        if ($this->modelClass == null) {
            (new LogMessage())->writeError('No modelClass defined');
            return;
        }


        $model = (new ModelFactory())->getModelByClassName($this->modelClass);
        return $model;

    }
303233
public function getModel()
    {
        if (!$this->model) {
            $this->model = $this->add($this->model_name);
        }
        /** @type Model $this->model */
        if ($this->display_field) {
            $this->model->title_field = $this->display_field;
        }
        if ($this->table_alias) {
            $this->model->table_alias = $this->table_alias;
        }

        return $this->model;
    }
1355195
public function getModel()
    {
        if (is_null($this->_model)) {
            $modelClass = $this->modelClass;
            $this->_model = new $modelClass();
        }

        return $this->_model;
    }
897889
protected function findModel()
    {
        $class = $this->model;
        $query = $class::query();

        foreach ($this->input as $key => $value) {
            $where = is_array($value) ? 'whereIn' : 'where';
            $query->$where($key, $value);
        }

        return $query->get();
    }
785665
public function get()
    {
        $modelResult = $this->getRequest()->request(
            'GET',
            $this->getRequestUrl('models')
        );

        return $this->getModelsFromResult($modelResult);
    }
561086
public function roots()
    {
        $model = new $this->owner->modelClass();

        $this->owner
            ->andWhere([$model->leftAttribute => 1])
            ->addOrderBy([$model->primaryKey()[0] => SORT_ASC]);

        return $this->owner;
    }
175135
public function constrain()
	{
		return $this->related->whereEquals($this->relatedKey, $this->model->{$this->localKey});
	}
1273606
protected function relatedModel()
    {
        $yaml = app('decoy.elements')->getConfig();
        $model = array_get($yaml, $this->key.'.class')
            ?: array_get($yaml, $this->key.',model.class');

        return $model::find($this->value);
    }
1173225
public function create($related)
	{
		if($related instanceof $this->model)
		{
			$related->{$this->polymorphicType} = $this->parent->getClass();
		}
		else
		{
			$related[$this->polymorphicType] = $this->parent->getClass();
		}

		return parent::create($related);
	}
1292249
protected function getRelationshipInstance() : Relationship
    {
        $relation = $this->relationshipMethod;
        $entity = $this->parentEntity;
        $entityMap = Manager::getMapper($entity)->getEntityMap();

        return $entityMap->$relation($entity);
    }
29886
public function getModel()
    {
        if (!isset($this->_pk))
            throw new InvalidCallException('Invalid usage. You must call this method only if load method succeeds');

        if (isset($this->_model))
            return $this->_model;

        $class = $this->modelClass;
        return $this->_model = $class::findOne($this->_pk);
    }
115352
public function newRelatedInstanceFor(Model $parent)
    {
        $newInstance = $this->related->newInstance();

        if (is_array($this->localKey)) { //Check for multi-columns relationship
            $foreignKey = $this->getForeignKeyName();

            foreach ($this->localKey as $index => $key) {
                $newInstance->setAttribute($foreignKey[$index], $parent->{$key});
            }
        } else {
            return $newInstance->setAttribute($this->getForeignKeyName(), $parent->{$this->localKey});
        }
    }
1190334
public function getRelationalDataAndModels($model, $desired_relation)
    {
        // $relations = $model->getRelations();
        $relation = $this->trimCommonRelationEndings($desired_relation);
        // Grab all the model relationships that don't return as a collection
        if (method_exists($model, $relation)) {
            // We have our relation, return it
            return $this->getResolvedRelationship($model, $relation);
        } elseif (method_exists($model, $relation.'s')) {
            // We have our relations, return it
            return $this->getResolvedRelationship($model, $relation.'s');
        } elseif (method_exists($model, $relation.'s')) {
            return $this->getResolvedRelationship($model, $relation.'s');
        }
        // don't return because clearly, nothing matches what we need.
    }
1091179
public static function related_class($relation)
	{
		$class = get_called_class();

		foreach (static::$_valid_relations as $rel_name => $rel_class)
		{
			if (property_exists($class, '_'.$rel_name))
			{
				if (isset(static::${'_'.$rel_name}[$relation]))
				{
					return static::${'_'.$rel_name}[$relation]['model_to'];
				}
			}
		}

		return null;
	}