Merge pull request #10959 from creative-commoners/pulls/4.13/add-fixed-fields

FIX Ensure all fixed fields are added
This commit is contained in:
Sabina Talipova 2023-09-26 12:00:59 +13:00 committed by GitHub
commit 071d8b7b09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

View File

@ -207,7 +207,11 @@ class DataQuery
$queriedColumns = $this->queriedColumns; $queriedColumns = $this->queriedColumns;
} }
if ($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; $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'