ENHANCEMENT Added has_many/many_many test cases for GridField

This commit is contained in:
Ingo Schommer 2012-02-29 16:06:46 +01:00
parent 759f550434
commit dd9f2a255d
2 changed files with 38 additions and 4 deletions

View File

@ -14,7 +14,8 @@ class Company extends DataObject {
);
public static $has_one = array(
'RelationFieldsTestPage' => 'RelationFieldsTestPage'
'RelationFieldsTestPage' => 'RelationFieldsTestPage',
'GridFieldTestPage' => 'GridFieldTestPage'
);
public static $has_many = array(
@ -22,7 +23,8 @@ class Company extends DataObject {
);
static $belongs_many_many = array(
'RelationFieldsTestPages' => 'RelationFieldsTestPage'
'RelationFieldsTestPages' => 'RelationFieldsTestPage',
'GridFieldTestPage' => 'GridFieldTestPage'
);
public static $summary_fields = array('Name', 'Category', 'Revenue', 'CEO');

View File

@ -1,5 +1,17 @@
<?php
class GridFieldTestPage extends Page {
static $has_one = array(
"HasOneCompany" => "Company",
);
static $has_many = array(
"HasManyCompanies" => "Company",
);
static $many_many = array(
"ManyManyCompanies" => "Company",
);
public function requireDefaultRecords() {
parent::requireDefaultRecords();
@ -27,10 +39,30 @@ class GridFieldTestPage extends Page {
$config->addComponent(new GridFieldAction_Delete());
$config->addComponent(new GridFieldAction_Edit());
$config->addComponent($forms = new GridFieldPopupForms());
$grid = new GridField('Companies', 'Companies', new DataList('Company'),$config);
$fields->addFieldToTab('Root.NoRelation', $grid);
$fields->addFieldToTab('Root.GridField', $grid);
$config = new GridFieldConfig();
$config->addComponent(new GridFieldDefaultColumns());
$config->addComponent(new GridFieldSortableHeader());
$config->addComponent(new GridFieldPaginator);
$config->addComponent(new GridFieldFilter());
$config->addComponent(new GridFieldAction_Delete());
$config->addComponent(new GridFieldAction_Edit());
$config->addComponent(new GridFieldRelationAdd('Name'));
$grid = new GridField('HasManyCompanies', 'HasManyCompanies', new DataList('Company'),$config);
$fields->addFieldToTab('Root.HasMany', $grid);
$config = new GridFieldConfig();
$config->addComponent(new GridFieldDefaultColumns());
$config->addComponent(new GridFieldSortableHeader());
$config->addComponent(new GridFieldPaginator);
$config->addComponent(new GridFieldFilter());
$config->addComponent(new GridFieldAction_Delete());
$config->addComponent(new GridFieldAction_Edit());
$config->addComponent(new GridFieldRelationAdd('Name'));
$grid = new GridField('ManyManyCompanies', 'ManyManyCompanies', new DataList('Company'),$config);
$fields->addFieldToTab('Root.ManyMany', $grid);
return $fields;
}