Commit 22b5494f authored by Benjamin Morel's avatar Benjamin Morel

Fix JOIN with no condition bug

parent e5d1edc2
......@@ -1327,9 +1327,11 @@ class QueryBuilder
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;
}
......
......@@ -92,11 +92,22 @@ class QueryBuilderTest extends DbalTestCase
$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);
......
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