Bugfix: fixed inheritance breaks filtering if relations are included (issue #3610)

This commit is contained in:
g4b0 2014-11-10 17:32:58 +01:00
parent 646a57c324
commit 239ed66eaf
2 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -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() {