mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '5.0' into 5.1
This commit is contained in:
commit
24db72a5f5
@ -603,6 +603,7 @@ class DataQuery
|
|||||||
$schema = DataObject::getSchema();
|
$schema = DataObject::getSchema();
|
||||||
$databaseFields = $schema->databaseFields($tableClass, false);
|
$databaseFields = $schema->databaseFields($tableClass, false);
|
||||||
$compositeFields = $schema->compositeFields($tableClass, false);
|
$compositeFields = $schema->compositeFields($tableClass, false);
|
||||||
|
$tableName = $schema->tableName($tableClass);
|
||||||
unset($databaseFields['ID']);
|
unset($databaseFields['ID']);
|
||||||
foreach ($databaseFields as $k => $v) {
|
foreach ($databaseFields as $k => $v) {
|
||||||
if ((is_null($columns) || in_array($k, $columns ?? [])) && !isset($compositeFields[$k])) {
|
if ((is_null($columns) || in_array($k, $columns ?? [])) && !isset($compositeFields[$k])) {
|
||||||
@ -618,12 +619,12 @@ class DataQuery
|
|||||||
$query->selectField($quotedField, $k);
|
$query->selectField($quotedField, $k);
|
||||||
}
|
}
|
||||||
$dbO = Injector::inst()->create($v, $k);
|
$dbO = Injector::inst()->create($v, $k);
|
||||||
|
$dbO->setTable($tableName);
|
||||||
$dbO->addToQuery($query);
|
$dbO->addToQuery($query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($compositeFields as $k => $v) {
|
foreach ($compositeFields as $k => $v) {
|
||||||
if ((is_null($columns) || in_array($k, $columns ?? [])) && $v) {
|
if ((is_null($columns) || in_array($k, $columns ?? [])) && $v) {
|
||||||
$tableName = $schema->tableName($tableClass);
|
|
||||||
$dbO = Injector::inst()->create($v, $k);
|
$dbO = Injector::inst()->create($v, $k);
|
||||||
$dbO->setTable($tableName);
|
$dbO->setTable($tableName);
|
||||||
$dbO->addToQuery($query);
|
$dbO->addToQuery($query);
|
||||||
|
@ -139,6 +139,8 @@ class DBClassName extends DBEnum
|
|||||||
if ($record instanceof DataObject) {
|
if ($record instanceof DataObject) {
|
||||||
$this->record = $record;
|
$this->record = $record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDefault()
|
public function getDefault()
|
||||||
|
@ -68,5 +68,7 @@ class DBPrimaryKey extends DBInt
|
|||||||
if ($record instanceof DataObject) {
|
if ($record instanceof DataObject) {
|
||||||
$this->object = $record;
|
$this->object = $record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -384,8 +384,9 @@ class DataQueryTest extends SapphireTest
|
|||||||
// Including filter on parent table only doesn't pull in second
|
// Including filter on parent table only doesn't pull in second
|
||||||
$query = new DataQuery(DataQueryTest\DataObjectAddsToQuery::class);
|
$query = new DataQuery(DataQueryTest\DataObjectAddsToQuery::class);
|
||||||
$result = $query->getFinalisedQuery();
|
$result = $query->getFinalisedQuery();
|
||||||
// The `DBFieldAddsToQuery` test field removes itself from the select query
|
// The `DBFieldAddsToQuery` test field adds a new field to the select query
|
||||||
$this->assertArrayNotHasKey('FieldTwo', $result->getSelect());
|
$this->assertArrayHasKey('FieldTwo2', $result->getSelect());
|
||||||
|
$this->assertSame('"DataQueryTest_AddsToQuery"."FieldTwo"', $result->getSelect()['FieldTwo2']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,13 +4,14 @@ namespace SilverStripe\ORM\Tests\DataQueryTest;
|
|||||||
|
|
||||||
use SilverStripe\Dev\TestOnly;
|
use SilverStripe\Dev\TestOnly;
|
||||||
use SilverStripe\ORM\FieldType\DBText;
|
use SilverStripe\ORM\FieldType\DBText;
|
||||||
|
use SilverStripe\ORM\Queries\SQLSelect;
|
||||||
|
|
||||||
class DBFieldAddsToQuery extends DBText implements TestOnly
|
class DBFieldAddsToQuery extends DBText implements TestOnly
|
||||||
{
|
{
|
||||||
public function addToQuery(&$query)
|
public function addToQuery(&$query)
|
||||||
{
|
{
|
||||||
$select = $query->getSelect();
|
// Add a new item, to validate that tableName and name are set correctly.
|
||||||
unset($select[$this->name]);
|
/** @var SQLSelect $query */
|
||||||
$query->setSelect($select);
|
$query->addSelect([$this->name . '2' => '"' . $this->tableName . '"."' . $this->name . '"']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user