Unverified Commit d6992ae0 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #3832 from BenMorel/join-no-on

Fix JOIN with no condition bug
parents e5d1edc2 22b5494f
...@@ -1327,9 +1327,11 @@ class QueryBuilder ...@@ -1327,9 +1327,11 @@ class QueryBuilder
if (array_key_exists($join['joinAlias'], $knownAliases)) { if (array_key_exists($join['joinAlias'], $knownAliases)) {
throw QueryException::nonUniqueAlias($join['joinAlias'], array_keys($knownAliases)); throw QueryException::nonUniqueAlias($join['joinAlias'], array_keys($knownAliases));
} }
$sql .= ' ' . strtoupper($join['joinType']) $sql .= ' ' . strtoupper($join['joinType'])
. ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias'] . ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias'];
. ' ON ' . ((string) $join['joinCondition']); if ($join['joinCondition'] !== null) {
$sql .= ' ON ' . $join['joinCondition'];
}
$knownAliases[$join['joinAlias']] = true; $knownAliases[$join['joinAlias']] = true;
} }
......
...@@ -92,11 +92,22 @@ class QueryBuilderTest extends DbalTestCase ...@@ -92,11 +92,22 @@ class QueryBuilderTest extends DbalTestCase
$qb->select('u.*', 'p.*') $qb->select('u.*', 'p.*')
->from('users', 'u') ->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); 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 public function testSelectWithInnerJoin() : void
{ {
$qb = new QueryBuilder($this->conn); $qb = new QueryBuilder($this->conn);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment