Fix SQLConditionalExpression::getJoins so it always adds explicit aliases

This is a revert of https://github.com/silverstripe/silverstripe-framework/pull/8956
This commit is contained in:
Serge Latyntcev 2019-05-06 15:19:21 +12:00 committed by Guy Sartorelli
parent 3b758a8a4c
commit e07671a890
No known key found for this signature in database
GPG Key ID: F313E3B9504D496A
2 changed files with 6 additions and 10 deletions

View File

@ -287,14 +287,7 @@ abstract class SQLConditionalExpression extends SQLExpression
continue;
}
if (preg_match('/AS\s+(?:"[^"]+"|[A-Z0-9_]+)\s*$/i', $join ?? '')) {
// custom aliases override the ones defined through array keys
// this is only meant to keep backward compatibility with SS <= 4.3,
// to be removed in SS5
continue;
}
$trimmedAlias = trim($alias ?? '', '"');
$trimmedAlias = trim($alias, '"');
if ($trimmedAlias !== trim($join ?? '', '"')) {
$joins[$alias] = "{$join} AS \"{$trimmedAlias}\"";

View File

@ -814,15 +814,18 @@ class SQLSelectTest extends SapphireTest
$sql
);
// This feature is a bug that used to exist in SS4 and was removed in SS5
// so now we test it does not exist and we end up with incorrect SQL because of that
// In SS4 the "explicitAlias" would be ignored
$query = SQLSelect::create('*', [
'MyTableAlias' => '"MyTable"',
'ignoredAlias' => ', (SELECT * FROM "MyTable" where "something" = "whatever") as "CrossJoin"'
'explicitAlias' => ', (SELECT * FROM "MyTable" where "something" = "whatever") as "CrossJoin"'
]);
$sql = $query->sql();
$this->assertSQLEquals(
'SELECT * FROM "MyTable" AS "MyTableAlias" , ' .
'(SELECT * FROM "MyTable" where "something" = "whatever") as "CrossJoin"',
'(SELECT * FROM "MyTable" where "something" = "whatever") as "CrossJoin" AS "explicitAlias"',
$sql
);
}