Hey Folks,
I'm relatively new to SilverStripe and I'm trying to create a site that has a Teams page and a Match Report page. There is a one to many relationship between the two with one Team able to have many MatchReports. Match Report is also a sub-page of Team only.
Now I've a few issues here but I think they are all related. On an individual match report page I want to have a teaser for the previous report for that Team. Now I can sort it so that the reports come in descending order but for the life of me I cannot find out how to narrow the field to just the reports for that one team. There will be multiple teams, each with their own subsection of reports, and each report should only find the other reports for that team. I've tried a few different options to no avail so I'm hoping that someone can shed light on this. The latest code is below. It doesn't break but it doesn't work either.
class MatchReport extends Page {
private static $can_be_root = false;
private static $db = array(
'Author' => 'Varchar',
'Teaser' => 'Text',
'Date' => 'Date',
);
private static $has_one = array (
'Image' => 'Image',
'Team' => 'Team',
);
....
class MatchReport_Controller extends Page_Controller {
public function PreviousArticle() {
return MatchReport::get()
->filter(array('Date:LessThan' => $this->Date, 'TeamID' => $this->Parent()->ID ))
->sort('Date', 'DESC')
->limit(1);
}
}
class Team extends Page {
private static $can_be_root = false;
private static $allowed_children = array('MatchReport');
private static $db = array (
);
private static $has_many = array(
'Results' => 'MatchResult',
'TrainingTimes' => 'TrainingTime',
'Fixtures' => 'Fixture',
'MatchReports' => 'MatchReport',
);
.....
Any advice or help would be greatly appreciated. Thanks!