BUGFIX: Don't create unnecessary aliases in generated SQL.

This commit is contained in:
Sam Minnee 2011-10-29 17:06:42 +13:00
parent ff9b9e17af
commit c8ce6f9f55
2 changed files with 4 additions and 3 deletions

View File

@ -467,7 +467,8 @@ class SQLQuery {
else if(sizeof($join['filter']) == 1) $filter = $join['filter'][0];
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";
}
}

View File

@ -218,8 +218,8 @@ class SQLQueryTest extends SapphireTest {
$query->leftJoin( 'MyLastTable', 'MyOtherTable.ID = MyLastTable.ID' );
$this->assertEquals( 'SELECT * FROM MyTable '.
'INNER JOIN "MyOtherTable" AS "MyOtherTable" ON MyOtherTable.ID = 2 '.
'LEFT JOIN "MyLastTable" AS "MyLastTable" ON MyOtherTable.ID = MyLastTable.ID',
'INNER JOIN "MyOtherTable" ON MyOtherTable.ID = 2 '.
'LEFT JOIN "MyLastTable" ON MyOtherTable.ID = MyLastTable.ID',
$query->sql()
);