From f1a9c92784eb029e4c9031db39836c97417f5357 Mon Sep 17 00:00:00 2001 From: Nicolaas Date: Sat, 30 May 2020 13:16:11 +1200 Subject: [PATCH] MINOR: better example --- docs/HasManyExample.md | 49 ++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/docs/HasManyExample.md b/docs/HasManyExample.md index ef37677..320e8f5 100644 --- a/docs/HasManyExample.md +++ b/docs/HasManyExample.md @@ -2,28 +2,38 @@ has_many Example ================= ```php + 'TestObject', - ]; + private static $has_many = [ + 'TestObjects' => 'TestObject', + ]; - public function getCMSFields() - { - $fields = parent::getCMSFields(); - - $conf = GridFieldConfig_RecordEditor::create(10); - $conf->addComponent(new GridFieldSortableRows('SortOrder')); + public function getCMSFields() + { + $fields = parent::getCMSFields(); + + $conf = GridFieldConfig_RelationEditor::create(10); + $conf->addComponent(new GridFieldSortableRows('SortOrder')); - $fields->addFieldToTab('Root.TestObjects', new GridField('TestObjects', 'TestObjects', $this->TestObjects(), $conf)); + $fields->addFieldToTab( + 'Root.TestObjects', + GridField::create( + 'TestObjects', + 'TestObjects', + $this->TestObjects(), + $conf + ) + ); - return $fields; - } + return $fields; + } } @@ -32,15 +42,18 @@ use SilverStripe\ORM\DataObject; class TestObject extends DataObject { - private static $db = [ - 'Title' => 'Text', - 'SortOrder' => 'Int', - ]; + private static $db = [ + 'Title' => 'Text', + 'SortOrder' => 'Int', + ]; + private static $indexes = [ + 'SortOrder' => true, + ]; private static $has_one = [ 'Parent' => 'TestPage', ]; - private static $default_sort = 'SortOrder'; + private static $default_sort = 'SortOrder'; } ```