Add union

@param QueryBuilderHandler $query
@param string|null $unionType

@return static $this
199459
public function union(QueryBuilderHandler $query, ?string $unionType = self::UNION_TYPE_NONE): IQueryBuilderHandler
    {
        $statements = $query->getStatements();

        if (\count($statements['unions']) > 0) {
            $this->statements['unions'] = $statements['unions'];
            unset($statements['unions']);
            $query->setStatements($statements);
        }

        $this->statements['unions'][] = [
            'query' => $query,
            'type'  => $unionType,
        ];

        return $this;
    }
1031042
private function addPerformanceJoinsToQueryBuilder(QueryBuilder $queryBuilder)
    {
        $queryBuilder
            ->select(['p', 'pa', 'pc', 'rpc', 'i'])
            ->leftJoin('p.principalImage', 'pa')
            ->leftJoin('p.priceCurrency', 'pc')
            ->leftJoin('p.reducedPriceCurrency', 'rpc')
            ->leftJoin('p.images', 'i')
            ->groupBy('p.id');
    }
339879
public function compileSelect(Builder $query)
    {
        $sql = parent::compileSelect($query);

        if ($query->unions) {
            $sql = '(' .$sql .') ' .$this->compileUnions($query);
        }

        return $sql;
    }
1157633
public function addJoin($key, array $parameters, $joinType = null)
    {
        if ( ! is_null($joinType)) {

            if ($joinType == 'join' || stripos($joinType, 'inner') !== false) {
                $this->joinTypes[$key] = 'join';
            } elseif (stripos($joinType, 'right') !== false) {
                $this->joinTypes[$key] = 'rightJoin';
            } else {
                unset( $this->joinTypes[$key] );
            }
        }

        $this->joins[$key] = $parameters;

        return $this;
    }
198312
protected function addJoinTable(Select $query)
    {
        $relationTable = $this->getRelationTable();
        $table = $this->getParentTableName();
        $pmk = $this->getParentPrimaryKey();
        $rfk = $this->getRelatedForeignKey();
        $query->join(
            $relationTable,
            "rel.{$rfk} = {$table}.{$pmk}",
            null,
            'rel'
        );
        return $this;
    }
598486
public function join($joinType, $alias, $table, $condition = null, $prefix = null)
    {
        $this->getQueryHelper()->addTable($alias, $table, $condition, $joinType, $prefix);

        return $this;
    }
176135
public function union(BaseQueryRelateContract $queryRelate, bool $unionAll = true): BaseQueryRelateContract
    {
        $this->query = $this->query->union($queryRelate->getQuery(), $unionAll);

        return $this;
    }
291184
public static function addRelationship($query, $relationship)
    {
        $property = $query->getRepository()->getDescription()->getProperty($relationship);

        switch (true) {
            case $property->isManyToOne() :
                return self::_parseManyToOne($query, $property);
            case $property->isManyToMany() :
                return self::_parseManyToMany($query, $property);
            case $property->isOneToMany() :
                return self::_parseOneToMany($query, $property);

        }
    }
1334208
public function union(): self
    {
        $query = new self;
        $query->clauses = $this->clauses->add(
            new Clause\UnionClause
        );

        return $query;
    }
1053786
protected function performJoin(Builder $query = null)
    {
        $query = $query ?: $this->query;

        $ownerKey = $this->getQualifiedOwnerKeyName();

        $query->join($this->throughChild->getTable(), $ownerKey , '=', $this->getQualifiedFirstKeyName());
        $query->select([
            '*' => $this->related->qualifyColumn('*'),
            $this->secondKey => $this->throughChild->getQualifiedKeyName().' as '.$this->secondKey
        ]);

        if ($this->throughChildSoftDeletes()) {
            $query->whereNull($this->throughChild->getQualifiedDeletedAtColumn());
        }
    }
621076
public function withQuery($query)
    {
        $new = clone $this;
        try {
            $new->setQuery($query);
        } catch (InvalidArgumentException $ex) {
            throw new InvalidArgumentException('Invalid query provided.', null, $ex);
        }

        return $new;
    }
1275094
public function merge($query): self
    {
        $pairs = $this->pairs;
        foreach (QueryString::parse($this->filterComponent($query), $this->separator, PHP_QUERY_RFC3986) as $pair) {
            $pairs = $this->addPair($pairs, $pair);
        }

        if ($pairs === $this->pairs) {
            return $this;
        }

        $clone = clone $this;
        $clone->pairs = $pairs;

        return $clone;
    }
712334
public function union($sql)
    {
        if (isset($this->query['union']) && is_string($this->query['union'])) {
            $this->query['union'][] = $this->query['union'];
        }

        $this->query['union'][] = $sql;

        return $this;
    }
1033662
protected function performJoins(Builder $query = null)
    {
        $query = $query ?: $this->query;

        foreach ($this->throughParents as $i => $model) {
            $table = $model->getTable();

            $predecessor = $i > 0 ? $this->throughParents[$i - 1] : $this->related;

            $first = $table.'.'.$this->getForeignKeyName($predecessor);

            $second = $predecessor->getQualifiedKeyName();

            $query->join($table, $first, '=', $second);

            if ($this->hasSoftDeletes($model)) {
                $this->query->whereNull($model->getQualifiedDeletedAtColumn());
            }
        }
    }
96304
public function addNestedPostFieldQuery($query)
    {
        if (count($query->body)) {
            $body = $this->body ?: [];

            $this->body = array_merge($body, $query->body);
        }

        return $this;
    }
498920
public function addUnion($union)
    {
        if (null === $union)
            return $this;
        if (!isset($this->query['union'])) {
            $this->query['union'] = [];
        }
        $this->query['union'][] = $union;
        return $this;
    }
951212
public function mergeBindings(self $query)
    {
        $this->bindings = array_merge_recursive($this->bindings, $query->bindings);

        return $this;
    }