mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Backward compatible behaviour for SQLConditionalExpression::getJoins
This commit is contained in:
parent
523456ae09
commit
3d777cfb8a
@ -287,6 +287,13 @@ abstract class SQLConditionalExpression extends SQLExpression
|
|||||||
continue;
|
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, '"')) {
|
if ($trimmedAlias !== trim($join, '"')) {
|
||||||
|
@ -841,10 +841,22 @@ class SQLSelectTest extends SapphireTest
|
|||||||
$sql = $query->sql();
|
$sql = $query->sql();
|
||||||
|
|
||||||
$this->assertSQLEquals(
|
$this->assertSQLEquals(
|
||||||
'SELECT *
|
'SELECT *
|
||||||
FROM "MyTable" AS "MyTableAlias"
|
FROM "MyTable" AS "MyTableAlias"
|
||||||
LEFT JOIN "OtherTable" AS "OtherTableAlias" ON "Thing" = "OtherThing"',
|
LEFT JOIN "OtherTable" AS "OtherTableAlias" ON "Thing" = "OtherThing"',
|
||||||
$sql
|
$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
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user