mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Fix SQLQuery::queriedTables() and added test.
This commit is contained in:
parent
397d19f23b
commit
6915e58a39
@ -230,7 +230,7 @@ class SQLQuery {
|
||||
public function queriedTables() {
|
||||
$tables = array();
|
||||
foreach($this->from as $key => $tableClause) {
|
||||
if(is_array($tableClause)) $table = $tableClause['table'];
|
||||
if(is_array($tableClause)) $table = '"'.$tableClause['table'].'"';
|
||||
else if(is_string($tableClause) && preg_match('/JOIN +("[^"]+") +(AS|ON) +/i', $tableClause, $matches)) $table = $matches[1];
|
||||
else $table = $tableClause;
|
||||
|
||||
@ -455,6 +455,9 @@ class SQLQuery {
|
||||
* @return string
|
||||
*/
|
||||
function sql() {
|
||||
// TODO: Don't require this internal-state manipulate-and-preserve - let sqlQueryToString() handle the new syntax
|
||||
$origFrom = $this->from;
|
||||
|
||||
// Build from clauses
|
||||
foreach($this->from as $alias => $join) {
|
||||
// $join can be something like this array structure
|
||||
@ -468,9 +471,11 @@ class SQLQuery {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$sql = DB::getConn()->sqlQueryToString($this);
|
||||
if($this->replacementsOld) $sql = str_replace($this->replacementsOld, $this->replacementsNew, $sql);
|
||||
|
||||
$this->from = $origFrom;
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
|
@ -230,6 +230,18 @@ class VersionedTest extends SapphireTest {
|
||||
'Models w/o Versioned can have their own Version field.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that SQLQuery::queriedTables() applies the version-suffixes properly.
|
||||
*/
|
||||
public function testQueriedTables() {
|
||||
Versioned::reading_stage('Live');
|
||||
|
||||
$this->assertEquals(array(
|
||||
'VersionedTest_DataObject_Live',
|
||||
'VersionedTest_Subclass_Live',
|
||||
), DataObject::get('VersionedTest_DataObject')->dataQuery()->query()->queriedTables());
|
||||
}
|
||||
}
|
||||
|
||||
class VersionedTest_DataObject extends DataObject implements TestOnly {
|
||||
|
Loading…
Reference in New Issue
Block a user