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

GridFieldConfig::create | many_many | duplicate entries


Go to End
Reply


4 Posts   570 Views

Avatar
dacar

Community Member, 168 Posts

13 December 2013 at 12:35am

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.

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

	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

Community Member, 96 Posts

14 December 2013 at 8:48pm

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

Avatar
dacar

Community Member, 168 Posts

16 December 2013 at 9:40pm

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

Greetings, Carsten.

Avatar
Bereusei

Community Member, 96 Posts

18 December 2013 at 9:14pm

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