mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
commit
071d8b7b09
@ -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;
|
||||
|
||||
|
30
tests/php/ORM/DataQueryFixedFieldsTest.php
Normal file
30
tests/php/ORM/DataQueryFixedFieldsTest.php
Normal 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'));
|
||||
}
|
||||
}
|
4
tests/php/ORM/DataQueryFixedFieldsTest.yml
Normal file
4
tests/php/ORM/DataQueryFixedFieldsTest.yml
Normal file
@ -0,0 +1,4 @@
|
||||
SilverStripe\ORM\Tests\DataQueryTest\ObjectA:
|
||||
query1:
|
||||
Name: 'Only one object'
|
||||
ExtraFixedField: 'This is the field'
|
Loading…
Reference in New Issue
Block a user