diff --git a/code/Company.php b/code/Company.php index f160501..d5dcd20 100644 --- a/code/Company.php +++ b/code/Company.php @@ -22,6 +22,18 @@ class Company extends DataObject { 'Employees' => 'Employee' ); + public static $many_many = array( + 'PastEmployees' => 'Employee' + ); + + public static $many_many_extraFields = array( + 'PastEmployees' => array( + 'YearStart' => 'Int', + 'YearEnd' => 'Int', + 'Role' => 'Text', + ) + ); + static $belongs_many_many = array( 'RelationFieldsTestPages' => 'RelationFieldsTestPage', 'GridFieldTestPage' => 'GridFieldTestPage' diff --git a/code/Employee.php b/code/Employee.php index d7232ef..83bad43 100644 --- a/code/Employee.php +++ b/code/Employee.php @@ -15,6 +15,25 @@ class Employee extends DataObject { 'Company' => 'Company', 'ProfileImage' => 'Image' ); + + public static $belongs_many_many = array( + 'PastCompanies' => 'Company' + ); + + function getCMSFields() { + $fields = parent::getCMSFields(); + + if(method_exists('ManyManyList', 'getExtraFields')) { + $fields->addFieldToTab('Root.Main', + new NumericField('ManyMany[YearStart]', 'Year started (3.1, many-many only)') + ); + $fields->addFieldToTab('Root.Main', + new TextField('ManyMany[Role]', 'Role (3.1, many-many only)') + ); + } + + return $fields; + } public function requireDefaultRecords() { parent::requireDefaultRecords();