Commit 7175964c authored by Marco Pivetta's avatar Marco Pivetta

Merge pull request #679 from deeky666/DBAL-774

[DBAL-774] Fix QueryBuilder parsing order of joins
parents acbc6da4 d97c443d
......@@ -1312,7 +1312,9 @@ class QueryBuilder
. ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias']
. ' ON ' . ((string) $join['joinCondition']);
$knownAliases[$join['joinAlias']] = true;
}
foreach ($this->sqlParts['join'][$fromAlias] as $join) {
$sql .= $this->getSQLForJoins($join['joinAlias'], $knownAliases);
}
}
......
......@@ -678,6 +678,60 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$this->assertEquals('SELECT DISTINCT u.id FROM users u INNER JOIN permissions p ON p.user_id = u.id, articles a INNER JOIN comments c ON c.article_id = a.id WHERE (u.id = a.user_id) AND (p.read = 1)', $qb->getSQL());
}
/**
* @group DBAL-774
*/
public function testSelectWithJoinsWithMultipleOnConditionsParseOrder()
{
$qb = new QueryBuilder($this->conn);
$qb->select('a.id')
->from('table_a', 'a')
->join('a', 'table_b', 'b', 'a.fk_b = b.id')
->join('b', 'table_c', 'c', 'c.fk_b = b.id AND b.language = ?')
->join('a', 'table_d', 'd', 'a.fk_d = d.id')
->join('c', 'table_e', 'e', 'e.fk_c = c.id AND e.fk_d = d.id');
$this->assertEquals(
'SELECT a.id ' .
'FROM table_a a ' .
'INNER JOIN table_b b ON a.fk_b = b.id ' .
'INNER JOIN table_d d ON a.fk_d = d.id ' .
'INNER JOIN table_c c ON c.fk_b = b.id AND b.language = ? ' .
'INNER JOIN table_e e ON e.fk_c = c.id AND e.fk_d = d.id',
(string) $qb
);
}
/**
* @group DBAL-774
*/
public function testSelectWithMultipleFromsAndJoinsWithMultipleOnConditionsParseOrder()
{
$qb = new QueryBuilder($this->conn);
$qb->select('a.id')
->from('table_a', 'a')
->from('table_f', 'f')
->join('a', 'table_b', 'b', 'a.fk_b = b.id')
->join('b', 'table_c', 'c', 'c.fk_b = b.id AND b.language = ?')
->join('a', 'table_d', 'd', 'a.fk_d = d.id')
->join('c', 'table_e', 'e', 'e.fk_c = c.id AND e.fk_d = d.id')
->join('f', 'table_g', 'g', 'f.fk_g = g.id');
$this->assertEquals(
'SELECT a.id ' .
'FROM table_a a ' .
'INNER JOIN table_b b ON a.fk_b = b.id ' .
'INNER JOIN table_d d ON a.fk_d = d.id ' .
'INNER JOIN table_c c ON c.fk_b = b.id AND b.language = ? ' .
'INNER JOIN table_e e ON e.fk_c = c.id AND e.fk_d = d.id, ' .
'table_f f ' .
'INNER JOIN table_g g ON f.fk_g = g.id',
(string) $qb
);
}
public function testClone()
{
$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