Merge branch '4' into 5.0

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

View File

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

View File

@ -15,6 +15,7 @@ class DataQueryTest extends SapphireTest
protected static $fixture_file = 'DataQueryTest.yml'; protected static $fixture_file = 'DataQueryTest.yml';
protected static $extra_dataobjects = [ protected static $extra_dataobjects = [
DataQueryTest\DataObjectAddsToQuery::class,
DataQueryTest\ObjectA::class, DataQueryTest\ObjectA::class,
DataQueryTest\ObjectB::class, DataQueryTest\ObjectB::class,
DataQueryTest\ObjectC::class, DataQueryTest\ObjectC::class,
@ -378,6 +379,15 @@ class DataQueryTest extends SapphireTest
static::resetDBSchema(true); 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 * Tests that getFinalisedQuery can include all tables
*/ */

View File

@ -36,3 +36,8 @@ SilverStripe\ORM\Tests\DataQueryTest\ObjectH:
SortOrder: 2 SortOrder: 2
ManyTestEs: =>SilverStripe\ORM\Tests\DataQueryTest\ObjectE.query2 ManyTestEs: =>SilverStripe\ORM\Tests\DataQueryTest\ObjectE.query2
ManyTestIs: =>SilverStripe\ORM\Tests\DataQueryTest\ObjectI.query3 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,
];
}