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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Cannot edit relationship


Go to End


1022 Views

Avatar
UNISOLUTIONS

Community Member, 2 Posts

18 October 2012 at 3:41am

Edited: 18/10/2012 3:42am

Hi,

Is it possible to edit relationship using ListboxField? According to the documentation it is (AFAIU saveInto() tries to edit relationship), but it doesn't work for me.
Every time I try to create a new record, every item (every Category) is selected in ListboxField.
Saving does not work too - it does not do anything (but there are no errors too).

So the code is:

Event.php

class Event extends Page {

	static $default_parent = 'EventList';

	static $can_be_root = false;

	public static $db = array(...);

	public static $many_many = array(
		"Categories" => "Category",
	);

	public function getCMSFields() {
		...

		$categoryList = DataObject::get_one("CategoryList");
		$categories = Category::get()->where("ParentID = '".$categoryList->ID."'")->map()->toArray();
		$fields->addFieldToTab('Root.Main',
			ListboxField::create('Categories', 'Categories')
				->setMultiple(true)
				->setSource($categories)
		, 'Content');

		...

		return $fields;
	}

Category.php
class Category extends Page {

	static $default_parent = 'CategoryList';

	static $can_be_root = false;

	public static $db = array(
	);

	public static $belongs_many_many = array(
		"Events" => "Event",
	);

}