mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '5.1' into 5
This commit is contained in:
commit
b8665a70d5
@ -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) {
|
||||
|
@ -15,6 +15,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,
|
||||
@ -378,6 +379,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
|
||||
*/
|
||||
|
@ -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'
|
||||
|
16
tests/php/ORM/DataQueryTest/DBFieldAddsToQuery.php
Normal file
16
tests/php/ORM/DataQueryTest/DBFieldAddsToQuery.php
Normal 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);
|
||||
}
|
||||
}
|
16
tests/php/ORM/DataQueryTest/DataObjectAddsToQuery.php
Normal file
16
tests/php/ORM/DataQueryTest/DataObjectAddsToQuery.php
Normal 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,
|
||||
];
|
||||
}
|
Loading…
Reference in New Issue
Block a user