FIX Allow filtering on joined columns

This commit is contained in:
Will Rossiter 2013-06-08 20:29:36 +12:00
parent 0129e185b8
commit 9775204436
2 changed files with 16 additions and 6 deletions

View File

@ -181,7 +181,9 @@ abstract class SearchFilter extends Object {
}
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\"";

View File

@ -211,11 +211,7 @@ class DataListTest extends SapphireTest {
$this->assertEquals($list->Count(), $count);
}
public function testFilter() {
$this->markTestIncomplete();
}
public function testWhere() {
// We can use raw SQL queries with where. This is only recommended for advanced uses;
// 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() {
$id = $this->idFromFixture('DataObjectTest_SubTeam', 'subteam1');
$list = DataObjectTest_SubTeam::get()->filter('ID', $id);