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 /

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

SS3: Edit single DataObject (has_one relationship) in CMS without GridField

Go to End



Community Member, 166 Posts

14 March 2013 at 6:59pm


Is there a way of being able to edit a single DataObject (in a has_one relationship) in the CMS without having to engage GridField (and changing to a has_many relation)?

I have a DataObject in SiteConfig (has_one) relationship, and would like to be able to edit it.

Example code:

class MyImage extends DataObject
	static $db = array (
		'TitleText' => 'Text',

	static $has_one = array (
		'MyImageFile' => 'Image',

	public function getCMSFields()
		return new FieldList(
			new TextField('TitleText'),
			new UploadField('MyImageFile')


class CustomSiteConfig extends DataExtension{

	static $db = array();
	static $has_one = array(
		'DefaultMyImage' => 'MyImage'
	static $has_many = array(
	function updateCMSFields(FieldList $fields) {
		// What field do I need to include here to be able to edit a single MyImage DataObject?

		return $fields;

Is it possible for some kind of field to use MyImage.getCMSFields() to generate the appropriate fields in the CMS? Or is there a way of explicitly adding each member of the DataObject to the CMS e.g.

	// This doesn't seem to work...
	function updateCMSFields(FieldList $fields) {
		$fields->addFieldToTab('Root.MyImage', new TextField('DefaultMyImage.TitleText', 'Title'));
		$fields->addFieldToTab('Root.MyImage', new UploadField('DefaultMyImage.MyImageFile', 'My Image'));
		return $fields;

Thanks very much.