3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 264 Views |
-
SS3 has_many relations

25 July 2012 at 3:45am
I'm having a little trouble understanding how the new GridField replaces some of the old interfaces. I'm trying to manage a $has_many relation on a page but when I create a new record using the GridField it doesn't automatically create the relation (just shows a drop down)
My DataObject Looks like this
class FAQ extends DataObject {
static $db = array(
'Question' => 'Varchar',
'Answer' => 'HTMLText'
);
static $has_one = array (
'FaqPage' => 'FaqPage'
);
static $summary_fields = array(
'Question' => 'Question',
'Answer' => 'Answer'
);
}
and the page looks likeclass FaqPage extends Page {
/**
* Static vars
* ----------------------------------*/
static $description = 'Holds Frequently Asked Questions';/**
* Data model
* ----------------------------------*/static $has_may = array (
'FAQs' => 'FAQ'
);/**
* Common methods
* ----------------------------------*/public function getCMSFields() {
$fields = parent::getCMSFields();
$FAQ = FAQ::get()->filter(array('FaqPageID' => $this->ID));
$FAQField = new GridField("FAQs", "Frequently Asked Question", $FAQ, GridFieldConfig_RelationEditor::create());
$fields->addFieldToTab("Root.FAQs",$FAQField);
return $fields;
}
}
Not sure what I'm missing and the documentation doesn't appear to be clearThanks
| 264 Views | ||
|
Page:
1
|
Go to Top |

