Merge branch '4.13' into 4

This commit is contained in:
github-actions 2023-09-09 14:23:38 +00:00
commit e28457cfa7
5 changed files with 49 additions and 0 deletions

View File

@ -617,6 +617,8 @@ class DataQuery
} else {
$query->selectField($quotedField, $k);
}
$dbO = Injector::inst()->create($v, $k);
$dbO->addToQuery($query);
}
}
foreach ($compositeFields as $k => $v) {

View File

@ -18,6 +18,7 @@ class DataQueryTest extends SapphireTest
protected static $fixture_file = 'DataQueryTest.yml';
protected static $extra_dataobjects = [
DataQueryTest\DataObjectAddsToQuery::class,
DataQueryTest\ObjectA::class,
DataQueryTest\ObjectB::class,
DataQueryTest\ObjectC::class,
@ -381,6 +382,15 @@ class DataQueryTest extends SapphireTest
static::resetDBSchema(true);
}
public function testAddToQueryIsCalled()
{
// Including filter on parent table only doesn't pull in second
$query = new DataQuery(DataQueryTest\DataObjectAddsToQuery::class);
$result = $query->getFinalisedQuery();
// The `DBFieldAddsToQuery` test field removes itself from the select query
$this->assertArrayNotHasKey('FieldTwo', $result->getSelect());
}
/**
* Tests that getFinalisedQuery can include all tables
*/

View File

@ -36,3 +36,8 @@ SilverStripe\ORM\Tests\DataQueryTest\ObjectH:
SortOrder: 2
ManyTestEs: =>SilverStripe\ORM\Tests\DataQueryTest\ObjectE.query2
ManyTestIs: =>SilverStripe\ORM\Tests\DataQueryTest\ObjectI.query3
SilverStripe\ORM\Tests\DataQueryTest\DataObjectAddsToQuery:
obj1:
FieldOne: 'This is a value'
FieldTwo: 'This is also a value'

View File

@ -0,0 +1,16 @@
<?php
namespace SilverStripe\ORM\Tests\DataQueryTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\FieldType\DBText;
class DBFieldAddsToQuery extends DBText implements TestOnly
{
public function addToQuery(&$query)
{
$select = $query->getSelect();
unset($select[$this->name]);
$query->setSelect($select);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace SilverStripe\ORM\Tests\DataQueryTest;
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\DataObject;
class DataObjectAddsToQuery extends DataObject implements TestOnly
{
private static $table_name = 'DataQueryTest_AddsToQuery';
private static $db = [
'FieldOne' => 'Text',
'FieldTwo' => DBFieldAddsToQuery::class,
];
}