Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Ensure all fixed fields are added #10959

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'));
sabina-talipova marked this conversation as resolved.
Show resolved Hide resolved
}
Comment on lines +24 to +29
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have confirmed locally that this fails when the change to DataQuery is not added.

}
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'