mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Don't create unnecessary aliases in generated SQL.
This commit is contained in:
parent
ff9b9e17af
commit
c8ce6f9f55
@ -467,7 +467,8 @@ class SQLQuery {
|
|||||||
else if(sizeof($join['filter']) == 1) $filter = $join['filter'][0];
|
else if(sizeof($join['filter']) == 1) $filter = $join['filter'][0];
|
||||||
else $filter = "(" . implode(") AND (", $join['filter']) . ")";
|
else $filter = "(" . implode(") AND (", $join['filter']) . ")";
|
||||||
|
|
||||||
$this->from[$alias] = strtoupper($join['type']) . " JOIN \"{$join['table']}\" AS \"$alias\" ON $filter";
|
$aliasClause = ($alias != $join['table']) ? " AS \"$alias\"" : "";
|
||||||
|
$this->from[$alias] = strtoupper($join['type']) . " JOIN \"{$join['table']}\"$aliasClause ON $filter";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,8 +218,8 @@ class SQLQueryTest extends SapphireTest {
|
|||||||
$query->leftJoin( 'MyLastTable', 'MyOtherTable.ID = MyLastTable.ID' );
|
$query->leftJoin( 'MyLastTable', 'MyOtherTable.ID = MyLastTable.ID' );
|
||||||
|
|
||||||
$this->assertEquals( 'SELECT * FROM MyTable '.
|
$this->assertEquals( 'SELECT * FROM MyTable '.
|
||||||
'INNER JOIN "MyOtherTable" AS "MyOtherTable" ON MyOtherTable.ID = 2 '.
|
'INNER JOIN "MyOtherTable" ON MyOtherTable.ID = 2 '.
|
||||||
'LEFT JOIN "MyLastTable" AS "MyLastTable" ON MyOtherTable.ID = MyLastTable.ID',
|
'LEFT JOIN "MyLastTable" ON MyOtherTable.ID = MyLastTable.ID',
|
||||||
$query->sql()
|
$query->sql()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user