Skip to content

Commit

Permalink
Fix JOIN with no condition bug
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Jan 19, 2020
1 parent e5d1edc commit 22b5494
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/Doctrine/DBAL/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1327,9 +1327,11 @@ private function getSQLForJoins($fromAlias, array &$knownAliases)
if (array_key_exists($join['joinAlias'], $knownAliases)) {
throw QueryException::nonUniqueAlias($join['joinAlias'], array_keys($knownAliases));
}
$sql .= ' ' . strtoupper($join['joinType'])
. ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias']
. ' ON ' . ((string) $join['joinCondition']);
$sql .= ' ' . strtoupper($join['joinType'])
. ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias'];
if ($join['joinCondition'] !== null) {
$sql .= ' ON ' . $join['joinCondition'];
}
$knownAliases[$join['joinAlias']] = true;
}

Expand Down
13 changes: 12 additions & 1 deletion tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,22 @@ public function testSelectWithJoin() : void

$qb->select('u.*', 'p.*')
->from('users', 'u')
->Join('u', 'phones', 'p', $expr->eq('p.user_id', 'u.id'));
->join('u', 'phones', 'p', $expr->eq('p.user_id', 'u.id'));

self::assertEquals('SELECT u.*, p.* FROM users u INNER JOIN phones p ON p.user_id = u.id', (string) $qb);
}

public function testSelectWithJoinNoCondition() : void
{
$qb = new QueryBuilder($this->conn);

$qb->select('u.*', 'p.*')
->from('users', 'u')
->join('u', 'phones', 'p');

self::assertEquals('SELECT u.*, p.* FROM users u INNER JOIN phones p', (string) $qb);
}

public function testSelectWithInnerJoin() : void
{
$qb = new QueryBuilder($this->conn);
Expand Down

0 comments on commit 22b5494

Please sign in to comment.