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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

GridFieldConfig::create | many_many | duplicate entries


Reply

4 Posts   322 Views

Avatar
dacar

13 December 2013 at 12:35am Community Member, 168 Posts

Hi,

i am still working on an old problem. I have set up a gridfield for a many_many relation. Everything works fine, but if i want to "change relation status", the gridfield shows all items from page_mitarbeiter instead of mitarbeiter.

[url]http://stackoverflow.com/questions/19094863/multiple-rows-with-same-id-in-silverstripe-gridfield[/url]

   private static $many_many = array (
      'Mitarbeiter' => 'Mitarbeiter'
   );

   private static $many_many_extraFields = array(
      'Mitarbeiter' => array(
         'SortOrder' => "Int"
      )
   );

         $MitarbeiterFieldConfig = GridFieldConfig::create(200)->addComponents(
          new GridFieldToolbarHeader(),
          new GridFieldSortableHeader(),
          new GridFieldDataColumns(),
          new GridFieldDeleteAction('unlinkrelation'),
          new GridFieldSortableRows('SortOrder'),
          new GridFieldManyRelationHandler(), 'GridFieldPaginator'
          //new GridFieldPaginator(20)
         );

         $MitarbeiterField = new GridField("Mitarbeiter", "zuzuordnede Mitarbeiter", $this->Mitarbeiter(), $MitarbeiterFieldConfig);
         $fields->addFieldToTab('Root.Mitarbeiter', $MitarbeiterField);   

   public function Mitarbeiter() {
      $mitarbeiter = $this->getManyManyComponents('Mitarbeiter')->sort('SortOrder');
      return $mitarbeiter;
   }   

Can anybody help?

Avatar
Bereusei

14 December 2013 at 8:48pm Community Member, 94 Posts

I don't know, what you mean with relation status. Did you mean from many_many to has_many?

Avatar
dacar

16 December 2013 at 9:40pm Community Member, 168 Posts

Hi Bereusei, thanks for spending your time. I have attached two pictures to show, what i mean.

Greetings, Carsten.

Avatar
Bereusei

18 December 2013 at 9:14pm Community Member, 94 Posts

Sorry, I know very little about the sortable gridfield module. At least I can´t see weird things in your code.