mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
3b758a8a4c
commit
e07671a890
@ -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}\"";
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user