diff --git a/search/filters/SearchFilter.php b/search/filters/SearchFilter.php index b9d47a39e..7a02b0e66 100644 --- a/search/filters/SearchFilter.php +++ b/search/filters/SearchFilter.php @@ -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\""; diff --git a/tests/model/DataListTest.php b/tests/model/DataListTest.php index 4c571b478..e6e2b9941 100644 --- a/tests/model/DataListTest.php +++ b/tests/model/DataListTest.php @@ -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);