silverstripe/sapphire — pull request #213 by jthomerson (2012-03-08 20:47:50+00:00)
Title: Fix sqlquery joined table aliases

If you used SQLQuery join functions with aliases for the table names it caused
Versioned->augmentSQL to create invalid table names. For instance, if you did:

$query = new SQLQuery('"SiteTree".ID, "SiteTree".Title');
$query->from('"SiteTree"');
$query->where('"SiteTree".Locale', 'en');
$query->innerJoin('SiteTree', '"SiteTree"."ParentID" = pa1.ID AND pa1.URLSegment = \'some-page\'', 'pa1');
singleton('Versioned')->augmentSQL(&$query);
$query->execute();

This previously resulted in Versioned->augmentSQL renaming "pa1" to "pa1_Live"
which is not a table or table alias in the resulting SQL query.

The fix in this commit is to track table names separately from the aliases used
for tables. This allows Versioned->augmentSQL to iterate over these actual
table names regardless of what (if any) aliases are used for them.