Added many-many (plus extrafields) example

This commit is contained in:
Ingo Schommer 2013-01-15 00:43:43 +01:00
parent 247ebff56c
commit 432cc44a30
2 changed files with 31 additions and 0 deletions

View File

@ -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'

View File

@ -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();