Merge pull request #7602 from dhensby/pulls/3.5/fix-filter-any-inner-join

FIX ManyMany link table joined with LEFT JOIN
This commit is contained in:
Loz Calver 2017-11-16 13:48:07 +00:00 committed by GitHub
commit 13b02feed7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -726,7 +726,7 @@ class DataQuery {
list($parentClass, $componentClass, $parentField, $componentField, $relationTable) = $component; list($parentClass, $componentClass, $parentField, $componentField, $relationTable) = $component;
$parentBaseClass = ClassInfo::baseDataClass($parentClass); $parentBaseClass = ClassInfo::baseDataClass($parentClass);
$componentBaseClass = ClassInfo::baseDataClass($componentClass); $componentBaseClass = ClassInfo::baseDataClass($componentClass);
$this->query->addInnerJoin($relationTable, $this->query->addLeftJoin($relationTable,
"\"$relationTable\".\"$parentField\" = \"$parentBaseClass\".\"ID\""); "\"$relationTable\".\"$parentField\" = \"$parentBaseClass\".\"ID\"");
if (!$this->query->isJoinedTo($componentBaseClass)) { if (!$this->query->isJoinedTo($componentBaseClass)) {
$this->query->addLeftJoin($componentBaseClass, $this->query->addLeftJoin($componentBaseClass,

View File

@ -774,6 +774,15 @@ class DataListTest extends SapphireTest {
$this->assertEquals(1, $list->count()); $this->assertEquals(1, $list->count());
} }
public function testFilterAnyWithRelation() {
$list = DataObjectTest_Player::get();
$list = $list->filterAny(array(
'Teams.Title:StartsWith' => 'Team',
'ID:GreaterThan' => 0,
));
$this->assertCount(4, $list);
}
public function testFilterAnyMultipleArray() { public function testFilterAnyMultipleArray() {
$list = DataObjectTest_TeamComment::get(); $list = DataObjectTest_TeamComment::get();
$list = $list->filterAny(array('Name'=>'Bob', 'Comment'=>'This is a team comment by Bob')); $list = $list->filterAny(array('Name'=>'Bob', 'Comment'=>'This is a team comment by Bob'));