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'
|
'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(
|
static $belongs_many_many = array(
|
||||||
'RelationFieldsTestPages' => 'RelationFieldsTestPage',
|
'RelationFieldsTestPages' => 'RelationFieldsTestPage',
|
||||||
'GridFieldTestPage' => 'GridFieldTestPage'
|
'GridFieldTestPage' => 'GridFieldTestPage'
|
||||||
|
@ -15,6 +15,25 @@ class Employee extends DataObject {
|
|||||||
'Company' => 'Company',
|
'Company' => 'Company',
|
||||||
'ProfileImage' => 'Image'
|
'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() {
|
public function requireDefaultRecords() {
|
||||||
parent::requireDefaultRecords();
|
parent::requireDefaultRecords();
|
||||||
|
Loading…
Reference in New Issue
Block a user