mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Bugfix: fixed inheritance breaks filtering if relations are included (issue #3610)
This commit is contained in:
parent
646a57c324
commit
239ed66eaf
@ -610,8 +610,9 @@ class DataQuery {
|
||||
if(!$this->query->isJoinedTo($component)) {
|
||||
$has_one = array_flip($model->has_one());
|
||||
$foreignKey = $has_one[$component];
|
||||
$realModelClass = ClassInfo::table_for_object_field($modelClass, "{$foreignKey}ID");
|
||||
$this->query->addLeftJoin($component,
|
||||
"\"$component\".\"ID\" = \"{$modelClass}\".\"{$foreignKey}ID\"");
|
||||
"\"$component\".\"ID\" = \"{$realModelClass}\".\"{$foreignKey}ID\"");
|
||||
|
||||
/**
|
||||
* add join clause to the component's ancestry classes so that the search filter could search on
|
||||
|
@ -49,6 +49,14 @@ class DataQueryTest extends SapphireTest {
|
||||
$dq->sql());
|
||||
}
|
||||
|
||||
public function testApplyReplationDeepInheretence() {
|
||||
$newDQ = new DataQuery('DataQueryTest_E');
|
||||
//apply a relation to a relation from an ancestor class
|
||||
$newDQ->applyRelation('TestA');
|
||||
$this->assertTrue($newDQ->query()->isJoinedTo('DataQueryTest_C'));
|
||||
$this->assertContains('"DataQueryTest_A"."ID" = "DataQueryTest_C"."TestAID"', $newDQ->sql());
|
||||
}
|
||||
|
||||
public function testRelationReturn() {
|
||||
$dq = new DataQuery('DataQueryTest_C');
|
||||
$this->assertEquals('DataQueryTest_A', $dq->applyRelation('TestA'),
|
||||
@ -64,6 +72,9 @@ class DataQueryTest extends SapphireTest {
|
||||
'DataQuery::applyRelation should return the name of the related object.');
|
||||
$this->assertEquals('DataQueryTest_B', $dq->applyRelation('ManyTestBs'),
|
||||
'DataQuery::applyRelation should return the name of the related object.');
|
||||
$newDQ = new DataQuery('DataQueryTest_E');
|
||||
$this->assertEquals('DataQueryTest_A', $newDQ->applyRelation('TestA'),
|
||||
'DataQuery::applyRelation should return the name of the related object.');
|
||||
}
|
||||
|
||||
public function testRelationOrderWithCustomJoin() {
|
||||
|
Loading…
Reference in New Issue
Block a user