Merge branch '4.13' into 4

This commit is contained in:
github-actions 2023-09-30 14:23:58 +00:00
commit 919eeac3e2
3 changed files with 39 additions and 1 deletions

View File

@ -207,7 +207,11 @@ class DataQuery
$queriedColumns = $this->queriedColumns;
}
if ($queriedColumns) {
$queriedColumns = array_merge($queriedColumns, ['Created', 'LastEdited', 'ClassName']);
// Add fixed fields to the query
// ID is a special case and gets added separately later
$fixedFields = DataObject::config()->uninherited('fixed_fields');
unset($fixedFields['ID']);
$queriedColumns = array_merge($queriedColumns, array_keys($fixedFields));
}
$query = clone $this->query;

View File

@ -0,0 +1,30 @@
<?php
namespace SilverStripe\ORM\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataQuery;
class DataQueryFixedFieldsTest extends SapphireTest
{
protected static $fixture_file = 'DataQueryFixedFieldsTest.yml';
protected static $extra_dataobjects = [
DataQueryTest\ObjectA::class,
];
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
DataObject::config()->merge('fixed_fields', ['ExtraFixedField' => 'Varchar']);
static::tempDB()->resetDBSchema(static::$extra_dataobjects);
}
public function testDataQueryHasFixedFields()
{
$dataQuery = new DataQuery(DataQueryTest\ObjectA::class);
$dataQuery->setQueriedColumns(['Name']);
$this->assertSame(['This is the field'], $dataQuery->execute()->column('ExtraFixedField'));
}
}

View File

@ -0,0 +1,4 @@
SilverStripe\ORM\Tests\DataQueryTest\ObjectA:
query1:
Name: 'Only one object'
ExtraFixedField: 'This is the field'