Skip to content

Commit 21f015c

Browse files
authored
Added FULL JOIN support to QueryBuilder (#7310)
<!-- Fill in the relevant information below to help triage your pull request. --> | Q | A |------------- | ----------- | Type | feature | Fixed issues | #7301 #### Summary Added [FULL JOIN](https://www.postgresql.org/docs/current/queries-table-expressions.html#QUERIES-JOIN) support to QueryBuilder.
1 parent 8994ceb commit 21f015c

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/Query/Join.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ public static function right(string $table, string $alias, ?string $condition):
2929
{
3030
return new self('RIGHT', $table, $alias, $condition);
3131
}
32+
33+
public static function full(string $table, string $alias, ?string $condition): Join
34+
{
35+
return new self('FULL', $table, $alias, $condition);
36+
}
3237
}

src/Query/QueryBuilder.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,32 @@ public function rightJoin(string $fromAlias, string $join, string $alias, ?strin
891891
return $this;
892892
}
893893

894+
/**
895+
* Creates and adds a full join to the query.
896+
*
897+
* <code>
898+
* $qb = $conn->createQueryBuilder()
899+
* ->select('u.name')
900+
* ->from('users', 'u')
901+
* ->fullJoin('u', 'phonenumbers', 'p', 'p.is_primary = 1');
902+
* </code>
903+
*
904+
* @param string $fromAlias The alias that points to a from clause.
905+
* @param string $join The table name to join.
906+
* @param string $alias The alias of the join table.
907+
* @param string|null $condition The condition for the join.
908+
*
909+
* @return $this This QueryBuilder instance.
910+
*/
911+
public function fullJoin(string $fromAlias, string $join, string $alias, ?string $condition = null): self
912+
{
913+
$this->join[$fromAlias][] = Join::full($join, $alias, $condition);
914+
915+
$this->sql = null;
916+
917+
return $this;
918+
}
919+
894920
/**
895921
* Sets a new value for a column in a bulk update query.
896922
*

tests/Query/QueryBuilderTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ public function testSelectWithRightJoin(): void
157157
self::assertEquals('SELECT u.*, p.* FROM users u RIGHT JOIN phones p ON p.user_id = u.id', (string) $qb);
158158
}
159159

160+
public function testSelectWithFullJoin(): void
161+
{
162+
$qb = new QueryBuilder($this->conn);
163+
$expr = $qb->expr();
164+
165+
$qb->select('u.*', 'p.*')
166+
->from('users', 'u')
167+
->fullJoin('u', 'phones', 'p', $expr->eq('p.user_id', 'u.id'));
168+
169+
self::assertEquals('SELECT u.*, p.* FROM users u FULL JOIN phones p ON p.user_id = u.id', (string) $qb);
170+
}
171+
160172
public function testSelectWithAndWhereConditions(): void
161173
{
162174
$qb = new QueryBuilder($this->conn);

0 commit comments

Comments
 (0)