Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

Problems with many_many / belongs_many_many


Reply

3 Posts   700 Views

Avatar
eeerlend

17 December 2013 at 1:15pm Community Member, 2 Posts

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';
}

Avatar
eeerlend

17 December 2013 at 10:17pm Community Member, 2 Posts

Hi, I've solved this myself.

The problem was that a "Team" > belongs_many_many > Competition. It should be "FootballCompetition" instead of "Competition".

Avatar
eumesmo

2 June 2014 at 3:10am Community Member, 1 Post

Hi, i'm also developing a similar data model, but also include seasons, have you made it using seasons?