Jump to:

3429 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Many many relationships question.

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

Page: 1
Go to End
Author Topic: 305 Views
  • T3nD4n
    Avatar
    Community Member
    16 Posts

    Many many relationships question. Link to this post

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

    and

    class Partido extends Page {

       public static $db = array(
          "Fecha"=>"date",
          "Resultado"=>"Varchar"
       );

       public static $many_many = array(
          "Jugadores"=>"Jugador"
       );
       
       public function getCMSFields() {
          $fields = parent::getCMSFields();
          $config = GridFieldConfig_RelationEditor::create();
          $config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
                'Nombre' => 'Nombre',
                'Apellido'=> 'Apellido'
          ));
          
          $config->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchFields(array(
                'Nombre',
                'Apellido'))->setResultsFormat('$Nombre - $Apellido');

          $jugadoresField = new GridField(
                'Jugadores', // Field name
                'Jugador', // Field title
                $this->Jugadores(),
                $config
          );
          
          $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.

    305 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.