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

Many many relationships question.




16 May 2013 at 8:01am Community Member, 16 Posts

First of all, sorry about my poor english.
I'am new in silverstripe and i have a question about relationships.

here are my classes:

class Jugador extends DataObject {
   static $db = array(
         'Nombre' => 'Varchar',
         'Apellido' => 'Varchar',
   static $belongs_many_many = array(
         'Partido' => 'Partido'


class Partido extends Page {

   public static $db = array(

   public static $many_many = array(
   public function getCMSFields() {
      $fields = parent::getCMSFields();
      $config = GridFieldConfig_RelationEditor::create();
            'Nombre' => 'Nombre',
            'Apellido'=> 'Apellido'
            'Apellido'))->setResultsFormat('$Nombre - $Apellido');

      $jugadoresField = new GridField(
            'Jugadores', // Field name
            'Jugador', // Field title
      $fields->addFieldToTab('Root.Jugadores', $jugadoresField);
      $dateField = new DateField('Fecha');
      $dateField->setConfig('showcalendar', true);
      $fields->addFieldToTab('Root.Main', $dateField, 'Content');
      $fields->addFieldToTab("Root.Main", new TextField('Resultado'), 'Content');
      return $fields;

so far i have a many many relation between "Partido" and "Jugador" (in english Match and players).
if i add a "partido" i can link existing "jugador" to this new partido and works fine.
the thing that i dont how to do is, that each player must have a diferent score on each "partido".
and i dont know how to add that relation in the classes.

any help will be appreciated.