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.

Archive /

Our old forums are still available as a read-only archive.

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

dataObject relationships


Go to End
Reply


2 Posts   1172 Views

Avatar
RobertM

Community Member, 26 Posts

15 August 2008 at 10:02pm

I have created a page with a 1-many dataObject storing the names of a project and who is responsible. I need to create another 1-many table, so that inside the popup when adding a new record there is a drop down menu to select which person. I don't want to create a page for each person, like it does in the tutorial. Can onyone help?

Avatar
carlossg

Community Member, 13 Posts

16 August 2008 at 4:53am

Hi,
Not sure to get you right
You mean adding a record in the projects table?
Take a look at this code.


class Person extends DataObject {
   [...]	
}

class Project extends DataObject {

    static $has_one = array(
		'Responsible' => 'Person'
	);

    function getCMSFields_forPopup() {
		$fields = new FieldSet();
		
		$mySet1 = DataObject::get('Person');
		$map1 = $mySet1 ? $mySet1->toDropDownMap('ID', 'Name') : '';
		$fields->push(new DropdownField('ResponsibleID',
								'Grupo',
								$map1
								));		
		return $fields;
	}   

   [...]	
}


class ProjectHolder extends Page {

function getCMSFields() {
    $fields = parent::getCMSFields();
    $projectstable = new ComplexTableField(
			$this,
			'Projects ',  //Relation Name that doesn't exists
			'Project ',
			array(
				'ProjectName' => 'ProjectName',				
				'Responsible.Name' => 'Responsible'
			),
			'getCMSFields_forPopup'		   
		);		
    $projectstable ->setParentClass(false);
    $fields->push($projectstable);
}		

Did it help?