Merge pull request #3622 from g4b0/3610-inheritance-breaks-filtering-if-relations-are-included-bugfix

Bugfix: fixed inheritance breaks filtering if relations are included
This commit is contained in:
Damian Mooyman 2014-11-11 23:57:21 +13:00
commit 4b2cd5f480
2 changed files with 13 additions and 1 deletions

View File

@ -610,8 +610,9 @@ class DataQuery {
if(!$this->query->isJoinedTo($component)) { if(!$this->query->isJoinedTo($component)) {
$has_one = array_flip($model->has_one()); $has_one = array_flip($model->has_one());
$foreignKey = $has_one[$component]; $foreignKey = $has_one[$component];
$realModelClass = ClassInfo::table_for_object_field($modelClass, "{$foreignKey}ID");
$this->query->addLeftJoin($component, $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 * 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()); $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() { public function testRelationReturn() {
$dq = new DataQuery('DataQueryTest_C'); $dq = new DataQuery('DataQueryTest_C');
$this->assertEquals('DataQueryTest_A', $dq->applyRelation('TestA'), $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.'); 'DataQuery::applyRelation should return the name of the related object.');
$this->assertEquals('DataQueryTest_B', $dq->applyRelation('ManyTestBs'), $this->assertEquals('DataQueryTest_B', $dq->applyRelation('ManyTestBs'),
'DataQuery::applyRelation should return the name of the related object.'); '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() { public function testRelationOrderWithCustomJoin() {