mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
Added many-many (plus extrafields) example
This commit is contained in:
parent
247ebff56c
commit
432cc44a30
@ -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'
|
||||
|
@ -16,6 +16,25 @@ class Employee extends DataObject {
|
||||
'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();
|
||||
$employeeSet = DataObject::get('Employee');
|
||||
|
Loading…
Reference in New Issue
Block a user