Merge pull request #8956 from open-sausages/pulls/4.3/custom-aliases-to-be

Backward compatible behaviour for SQLConditionalExpression::getJoins
This commit is contained in:
Guy Marriott 2019-05-03 09:40:25 +12:00 committed by GitHub
commit e7bb508391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -287,6 +287,13 @@ 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, '"');
if ($trimmedAlias !== trim($join, '"')) {

View File

@ -841,10 +841,22 @@ class SQLSelectTest extends SapphireTest
$sql = $query->sql();
$this->assertSQLEquals(
'SELECT *
FROM "MyTable" AS "MyTableAlias"
'SELECT *
FROM "MyTable" AS "MyTableAlias"
LEFT JOIN "OtherTable" AS "OtherTableAlias" ON "Thing" = "OtherThing"',
$sql
);
$query = SQLSelect::create('*', [
'MyTableAlias' => '"MyTable"',
'ignoredAlias' => ', (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"',
$sql
);
}
}