diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 5e86bd0acff5..836c2cc9fdbb 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -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; } @@ -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); } /** diff --git a/src/Illuminate/Database/Query/Grammars/Grammar.php b/src/Illuminate/Database/Query/Grammars/Grammar.php index e9a7fc8267a6..b8eed21e69fd 100755 --- a/src/Illuminate/Database/Query/Grammars/Grammar.php +++ b/src/Illuminate/Database/Query/Grammars/Grammar.php @@ -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; @@ -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); } @@ -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.'); } diff --git a/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php b/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php index da9941debfc7..3cf6350f2cd4 100755 --- a/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php @@ -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 @@ -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"); } diff --git a/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php b/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php index 8fa5d9952f63..ca1639ade402 100755 --- a/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/PostgresGrammar.php @@ -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; @@ -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"); } diff --git a/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php b/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php index 6fb32440c568..4a40dc49cbd1 100755 --- a/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php +++ b/src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php @@ -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; @@ -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'; diff --git a/src/Illuminate/Database/Query/JoinClause.php b/src/Illuminate/Database/Query/JoinClause.php index 2614bab0e900..aef1c9aa547d 100755 --- a/src/Illuminate/Database/Query/JoinClause.php +++ b/src/Illuminate/Database/Query/JoinClause.php @@ -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. * @@ -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(); diff --git a/src/Illuminate/Database/Query/JoinLateralClause.php b/src/Illuminate/Database/Query/JoinLateralClause.php new file mode 100644 index 000000000000..1be31d29626a --- /dev/null +++ b/src/Illuminate/Database/Query/JoinLateralClause.php @@ -0,0 +1,8 @@ +