mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '4.13' into 4
This commit is contained in:
commit
e28457cfa7
@ -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) {
|
||||||
|
@ -18,6 +18,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,
|
||||||
@ -381,6 +382,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
|
||||||
*/
|
*/
|
||||||
|
@ -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'
|
||||||
|
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