I have a problem with a $has_many relationship where not all the associated objects are being returned.
I'm attempting to create a relatively simple sporting league system on a SilverStripe site. The two classes I'm having trouble with are for Match and Team. Each match has two teams, a home team and an away team, setup like so:
static $has_one = array (
'HomeTeam' => 'Team',
'AwayTeam' => 'Team'
static $has_many = array (
'Matches' => 'Match'
Now the teams are actually created in the League page class, and there are dropdowns in the Match DOM to select the team for HomeTeam and another for AwayTeam. The Match class is created in a 'Round' page class.
My problem is it seems only the matches where the current team is set as the away team are being added to the has_many relationship. In other words calling $this->Matches in the Team class returns only matches where the team was set as the AwayTeam, and none of the matches where it set as the HomeTeam.
$this->HomeTeam; //returns the correct Team object fine
$this->AwayTeam; //returns the correct Team object fine
$this->Matches(); //only returns matches where the team is set as the away team, not the home team.
Since every team in the league can be a HomeTeam and an AwayTeam depending on the match, it doesn't seem feasible to create HomeTeam and AwayTeam sub-classes. Having the two $has_one relationships in the Match where a team could be either or both of those is having me scratching my head.
Should this be a $many_many relationship? I'm still learning SilverStripe and OOP in general and the $many_many relationship looks like a tricky one.
Thanks for your time.