Adds relation to query

@param string|array $relation

@return $this
@throws QueryException
501715
public function with($relation)
    {
        foreach ((array) $relation as $node) {
            $instance = $this->factory->build($this->model(), $node);
            $this->relations[$instance->name()] = $instance;
        }

        return $this;
    }
961614
protected function getNullForeignKeyFromRelation(string $relation): array
    {
        $key = $this->entityMap->getLocalKeys($relation);

        if (is_array($key)) {
            return $this->entityMap->getEmptyValueForLocalKey($relation);
        }

        if (is_null($key)) {
            throw new MappingException("Foreign key for relation $relation cannot be null");
        }

        return [
            $key => $this->entityMap->getEmptyValueForLocalKey($relation),
        ];
    }
408167
public static function make($relation)
    {
        if (static::isSupported($relation)) {
            $className = static::$relations[get_class($relation)]['className'];

            return new $className($relation);
        }
        throw new \LogicException('Unsupported relation: '.get_type_class($relation));
    }
686597
public function initRelation(array $models, $relation)
    {
        foreach ($models as $model)
        {
            // In the case of fetching nested relations, we will get an array
            // with the first key being the model we need, and the other being
            // the related model so we'll just take the first model out of the array.
            if (is_array($model)) $model = reset($model);

            $model->setRelation($relation, null);
        }

        return $models;
    }
1039270
protected function joinBelongsToMany(BelongsToMany $relation)
    {
        return $this->instance->join(
            $relation->getTable(),
            $relation->getParent()->getTable() . '.' . $relation->getParent()->getKeyName(),
            '=',
            $relation->getForeignKey()
        )->join(
            $relation->getRelated()->getTable(),
            $relation->getRelated()->getTable() . '.' . $relation->getRelated()->getKeyName(),
            '=',
            $relation->getOtherKey()
        );
    }
890032
protected function addSingleRelation(string $relation)
    {
        if (!in_array($relation, $this->singleRelations)) {
            $this->singleRelations[] = $relation;
        }
    }
507828
public function withCount($relations)
    {
        if (is_string($relations)) $relations = func_get_args();

        // If no columns are set, add the default * columns.
        if (is_null($this->query->columns)) {
            $this->query->select($this->query->from .'.*');
        }

        $relations = $this->parseRelations($relations);

        foreach ($relations as $name => $constraints) {
            $segments = explode(' ', $name);

            if ((count($segments) == 3) && (Str::lower($segments[1]) == 'as')) {
                list($name, $alias) = array($segments[0], $segments[2]);
            } else {
                unset($alias);
            }

            $relation = $this->getHasRelationQuery($name);

            // Here we will get the relationship count query and prepare to add it to the main query
            // as a sub-select. First, we'll get the "has" query and use that to get the relation
            // count query. We will normalize the relation name then append _count as the name.
            $query = $relation->getRelationCountQuery($relation->getRelated()->newQuery(), $this);

            call_user_func($constraints, $query);

            $this->mergeWheresToHas($query, $relation);

            $asColumn = snake_case(isset($alias) ? $alias : $name) .'_count';

            $this->selectSub($query->getQuery(), $asColumn);
        }

        return $this;
    }
876074
protected function addManyRelation(string $relation)
    {
        if (!in_array($relation, $this->manyRelations)) {
            $this->manyRelations[] = $relation;
        }
    }
1101202
public function load($relations)
    {
        if (count($this->items) > 0) {
            if (is_string($relations)) {
                $relations = func_get_args();
            }

            $query = $this->first()->newQuery()->with($relations);

            $this->items = $query->eagerLoadRelations($this->items);
        }

        return $this;
    }
1198834
public function queue($relation, array $args)
    {
        $this->queue[] = array(
            self::PARAM_RELATION => $relation,
            self::PARAM_ARGS => $args
        );
    }
548844
public function addRel($relation, $value)
        {
            if (is_string($relation)) {
                $this->_rel[$relation] = $value;
            }

            return $this;
        }
901785
public function addCloneableRelation($relation) {
		$relations = $this->getCloneableRelations();
		if (in_array($relation, $relations)) return;
		$relations[] = $relation;
		$this->cloneable_relations = $relations;
	}
160794
public function initRelation(array $models, $relation)
    {
        foreach ($models as $model) {
            $model->setRelation($relation, $this->getDefaultFor($model));
        }

        return $models;
    }
302381
public function addLink($uri, $relation = null)
    {
        /** @var Link $link */
        $link = $this->addChild('atom:link', 'links');
        $link->setUri($uri);
        if ($relation) {
            $link->setRelation($relation);
        }

        return $link;
    }
1290096
public function loadCount($relations)
    {
        $relations = is_string($relations) ? func_get_args() : $relations;

        $this->newCollection([$this])->loadCount($relations);

        return $this;
    }
366651
public static function buildDeleteRelationQuery(Relation $relation) {
        $query = "DELETE FROM `" . $relation->getTable() . "` ";
        $query .= "WHERE " . $relation->getLocalColumn() . " = :id;";
        return $query;
    }
1227986
protected function addPivotRelation(string $relation)
    {
        if (!in_array($relation, $this->pivotRelations)) {
            $this->pivotRelations[] = $relation;
        }
    }