Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Problems with many_many / belongs_many_many

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 604 Views
  • eeerlend
    Avatar
    Community Member
    2 Posts

    Problems with many_many / belongs_many_many Link to this post

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

  • eeerlend
    Avatar
    Community Member
    2 Posts

    Re: Problems with many_many / belongs_many_many Link to this post

    Hi, I've solved this myself.

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

  • eumesmo
    Avatar
    Community Member
    1 Post

    Re: Problems with many_many / belongs_many_many Link to this post

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

    604 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.