Jump to:

17452 Posts in 4473 Topics by 1971 members


SilverStripe Forums » Archive » dataObject relationships

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

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

Page: 1
Go to End
Author Topic: 1115 Views
  • RobertM
    Community Member
    26 Posts

    dataObject relationships Link to this post

    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?

  • carlossg
    Community Member
    13 Posts

    Re: dataObject relationships Link to this post

    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',
          return $fields;


    class ProjectHolder extends Page {

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

    Did it help?

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.