Skip to content

Commit

Permalink
Remove $lateral from JoinClause and use JoinLateralClause instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Bakke committed Feb 21, 2024
1 parent a247bc8 commit 64d099e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 26 deletions.
20 changes: 16 additions & 4 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public function joinLateral($query, string $as, string $type = 'inner'): static

$this->addBinding($bindings, 'join');

$this->joins[] = $this->newJoinClause($this, $type, new Expression($expression), true);
$this->joins[] = $this->newJoinLateralClause($this, $type, new Expression($expression));

return $this;
}
Expand Down Expand Up @@ -751,12 +751,24 @@ public function crossJoinSub($query, $as)
* @param \Illuminate\Database\Query\Builder $parentQuery
* @param string $type
* @param string $table
* @param bool $lateral
* @return \Illuminate\Database\Query\JoinClause
*/
protected function newJoinClause(self $parentQuery, $type, $table, $lateral = false)
protected function newJoinClause(self $parentQuery, $type, $table)
{
return new JoinClause($parentQuery, $type, $table, $lateral);
return new JoinClause($parentQuery, $type, $table);
}

/**
* Get a new join lateral clause.
*
* @param \Illuminate\Database\Query\Builder $parentQuery
* @param string $type
* @param string $table
* @return \Illuminate\Database\Query\JoinLateralClause
*/
protected function newJoinLateralClause(self $parentQuery, $type, $table)
{
return new JoinLateralClause($parentQuery, $type, $table);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Illuminate/Database/Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Database\Grammar as BaseGrammar;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Database\Query\JoinLateralClause;
use Illuminate\Support\Arr;
use RuntimeException;

Expand Down Expand Up @@ -182,7 +183,7 @@ protected function compileJoins(Builder $query, $joins)

$tableAndNestedJoins = is_null($join->joins) ? $table : '('.$table.$nestedJoins.')';

if ($join->lateral) {
if ($join instanceof JoinLateralClause) {
return $this->compileJoinLateral($join, $tableAndNestedJoins);
}

Expand All @@ -193,13 +194,13 @@ protected function compileJoins(Builder $query, $joins)
/**
* Compile a "lateral join" clause.
*
* @param \Illuminate\Database\Query\JoinClause $join
* @param \Illuminate\Database\Query\JoinLateralClause $join
* @param string $expression
* @return string
*
* @throws \RuntimeException
*/
public function compileJoinLateral(JoinClause $join, string $expression): string
public function compileJoinLateral(JoinLateralClause $join, string $expression): string
{
throw new RuntimeException('This database engine does not support lateral joins.');
}
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Illuminate\Database\Query\Grammars;

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Database\Query\JoinLateralClause;
use Illuminate\Support\Str;

class MySqlGrammar extends Grammar
Expand Down Expand Up @@ -237,11 +237,11 @@ protected function compileUpdateColumns(Builder $query, array $values)
/**
* Compile a "lateral join" clause.
*
* @param \Illuminate\Database\Query\JoinClause $join
* @param \Illuminate\Database\Query\JoinLateralClause $join
* @param string $expression
* @return string
*/
public function compileJoinLateral(JoinClause $join, string $expression): string
public function compileJoinLateral(JoinLateralClause $join, string $expression): string
{
return trim("{$join->type} join lateral {$expression} on true");
}
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Illuminate\Database\Query\Grammars;

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Database\Query\JoinLateralClause;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -389,11 +389,11 @@ protected function compileUpdateColumns(Builder $query, array $values)
/**
* Compile a "lateral join" clause.
*
* @param \Illuminate\Database\Query\JoinClause $join
* @param \Illuminate\Database\Query\JoinLateralClause $join
* @param string $expression
* @return string
*/
public function compileJoinLateral(JoinClause $join, string $expression): string
public function compileJoinLateral(JoinLateralClause $join, string $expression): string
{
return trim("{$join->type} join lateral {$expression} on true");
}
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Illuminate\Database\Query\Grammars;

use Illuminate\Database\Query\Builder;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Database\Query\JoinLateralClause;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -390,11 +390,11 @@ protected function compileUpdateWithJoins(Builder $query, $table, $columns, $whe
/**
* Compile a "lateral join" clause.
*
* @param \Illuminate\Database\Query\JoinClause $join
* @param \Illuminate\Database\Query\JoinLateralClause $join
* @param string $expression
* @return string
*/
public function compileJoinLateral(JoinClause $join, string $expression): string
public function compileJoinLateral(JoinLateralClause $join, string $expression): string
{
$type = $join->type == 'left' ? 'outer' : 'cross';

Expand Down
11 changes: 1 addition & 10 deletions src/Illuminate/Database/Query/JoinClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ class JoinClause extends Builder
*/
public $table;

/**
* Indicates if the join is a "lateral" join.
*
* @var bool
*/
public $lateral;

/**
* The connection of the parent query builder.
*
Expand Down Expand Up @@ -61,14 +54,12 @@ class JoinClause extends Builder
* @param \Illuminate\Database\Query\Builder $parentQuery
* @param string $type
* @param string $table
* @param bool $lateral
* @return void
*/
public function __construct(Builder $parentQuery, $type, $table, $lateral = false)
public function __construct(Builder $parentQuery, $type, $table)
{
$this->type = $type;
$this->table = $table;
$this->lateral = $lateral;
$this->parentClass = get_class($parentQuery);
$this->parentGrammar = $parentQuery->getGrammar();
$this->parentProcessor = $parentQuery->getProcessor();
Expand Down
8 changes: 8 additions & 0 deletions src/Illuminate/Database/Query/JoinLateralClause.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Illuminate\Database\Query;

class JoinLateralClause extends JoinClause
{
//
}

0 comments on commit 64d099e

Please sign in to comment.