Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

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: 1112 Views
  • RobertM
    Avatar
    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
    Avatar
    Community Member
    13 Posts

    Re: dataObject relationships Link to this post

    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?

    1112 Views
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.