Skip to content

Commit

Permalink
Merge branch '4.13' into 4
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 30, 2023
2 parents 5f72f9c + 071d8b7 commit 919eeac
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ORM/DataQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ public function getFinalisedQuery($queriedColumns = null)
$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;

Expand Down
30 changes: 30 additions & 0 deletions tests/php/ORM/DataQueryFixedFieldsTest.php
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions tests/php/ORM/DataQueryFixedFieldsTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SilverStripe\ORM\Tests\DataQueryTest\ObjectA:
query1:
Name: 'Only one object'
ExtraFixedField: 'This is the field'

0 comments on commit 919eeac

Please sign in to comment.