mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Allow filtering on joined columns
This commit is contained in:
parent
0129e185b8
commit
9775204436
@ -181,7 +181,9 @@ abstract class SearchFilter extends Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($candidateClass == 'DataObject') {
|
if($candidateClass == 'DataObject') {
|
||||||
user_error("Couldn't find field $this->name in any of $this->model's tables.", E_USER_ERROR);
|
// fallback to the provided name in the event of a joined column
|
||||||
|
// name (as the candidate class doesn't check joined records)
|
||||||
|
return $this->fullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "\"$candidateClass\".\"$this->name\"";
|
return "\"$candidateClass\".\"$this->name\"";
|
||||||
|
@ -212,10 +212,6 @@ class DataListTest extends SapphireTest {
|
|||||||
$this->assertEquals($list->Count(), $count);
|
$this->assertEquals($list->Count(), $count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFilter() {
|
|
||||||
$this->markTestIncomplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testWhere() {
|
public function testWhere() {
|
||||||
// We can use raw SQL queries with where. This is only recommended for advanced uses;
|
// We can use raw SQL queries with where. This is only recommended for advanced uses;
|
||||||
// if you can, you should use filter().
|
// if you can, you should use filter().
|
||||||
@ -580,6 +576,18 @@ class DataListTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFilterOnJoin() {
|
||||||
|
$list = DataObjectTest_TeamComment::get()
|
||||||
|
->leftJoin('DataObjectTest_Team',
|
||||||
|
'"DataObjectTest_Team"."ID" = "DataObjectTest_TeamComment"."TeamID"'
|
||||||
|
)->filter(array(
|
||||||
|
'Title' => 'Team 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertEquals(2, $list->count());
|
||||||
|
$this->assertEquals(array('Joe', 'Bob'), $list->column('Name'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testFilterAndExcludeById() {
|
public function testFilterAndExcludeById() {
|
||||||
$id = $this->idFromFixture('DataObjectTest_SubTeam', 'subteam1');
|
$id = $this->idFromFixture('DataObjectTest_SubTeam', 'subteam1');
|
||||||
$list = DataObjectTest_SubTeam::get()->filter('ID', $id);
|
$list = DataObjectTest_SubTeam::get()->filter('ID', $id);
|
||||||
|
Loading…
Reference in New Issue
Block a user