Commit d47a9412 authored by Steve Müller's avatar Steve Müller

fix parsing order of joins

parent 2f3ac5a9
...@@ -1312,7 +1312,9 @@ class QueryBuilder ...@@ -1312,7 +1312,9 @@ class QueryBuilder
. ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias'] . ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias']
. ' ON ' . ((string) $join['joinCondition']); . ' ON ' . ((string) $join['joinCondition']);
$knownAliases[$join['joinAlias']] = true; $knownAliases[$join['joinAlias']] = true;
}
foreach ($this->sqlParts['join'][$fromAlias] as $join) {
$sql .= $this->getSQLForJoins($join['joinAlias'], $knownAliases); $sql .= $this->getSQLForJoins($join['joinAlias'], $knownAliases);
} }
} }
......
...@@ -692,7 +692,44 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase ...@@ -692,7 +692,44 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
->join('a', 'table_d', 'd', 'a.fk_d = d.id') ->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('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); $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() public function testClone()
......
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