Hi!
I'm trying to build all data objects for my football web application, and have some issues with many_many relations. I've created a modelAdmin for managing teams and competitions, and I've listed the relevant objects below.
My problem is that I get the following error when trying to save a "Team" (Displayed as "Internal Server Error" in admin), but I got the db-entry for the Team.
Any help appreciated!
[17-Dec-2013 01:12:47] Error at framework/model/DataObject.php line 1849: Inverse component of Competition not found (Team) (http://localhost/admin/teams/Team/EditForm/field/Team/item/8)
[17-Dec-2013 01:12:47] Error at framework/model/DataObject.php line 1860: Orphaned $belongs_many_many value for Team.Competitions (http://localhost/admin/teams/Team/EditForm/field/Team/item/8)
[17-Dec-2013 01:12:47] Error at framework/model/DataQuery.php line 116: DataList::create Can't find data classes (classes linked to tables) for . Please ensure you run dev/build after creating a new DataObject. (http://localhost/admin/teams/Team/EditForm/field/Team/item/8)
[17-Dec-2013 01:12:47] Error at framework/core/Core.php line 152: singleton() Called without a class (http://localhost/admin/teams/Team/EditForm/field/Team/item/8)
[17-Dec-2013 01:12:47] Error at framework/core/Core.php line 154: singleton() passed bad class_name: NULL (http://localhost/admin/teams/Team/EditForm/field/Team/item/8)
[17-Dec-2013 01:12:47] Error at framework/control/injector/InjectionCreator.php line 18: Uncaught ReflectionException: Class does not exist (http://localhost/admin/teams/Team/EditForm/field/Team/item/8)
The classes
class Competition extends DataObject {
private static $db = array(
'Title' => 'Varchar',
'StartDate' => 'Date',
'EndDate' => 'Date'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
return $fields;
}
}
class FootballCompetition extends Competition {
private static $has_many = array(
'Matches' => 'Match'
);
private static $many_many = array(
'Teams' => 'Team'
);
}
class Team extends DataObject {
private static $db = array(
'Title' => 'Varchar',
'Shortname' => 'Varchar'
);
private static $has_many = array(
'MatchesHome' => 'Match.HomeTeam',
'MatchesAway' => 'Match.AwayTeam',
);
private static $belongs_many_many = array(
'Competitions' => 'Competition'
);
function getMatches() {
return DataObject::get('Match', "HomeTeamID = '$this->ID' OR AwayTeamID = '$this->ID'");
}
}
class TeamAdmin extends ModelAdmin {
private static $managed_models = array('Team');
private static $url_segment = 'teams';
private $menu_title = 'Team Admin';
}