0
votes

With this code the DataObject ID (InternalExternalLinkID) is not saved to the page when the CMS page is published, how to I automatically add the scaffolding from the dataobject and have the relationship saved (without manually doing onAfterWrite() as described at http://www.silverstripe.org/data-model-questions/show/11044):

class Page extends SiteTree {

    private static $has_one = array(
        'InternalExternalLink' => 'InternalExternalLink'
    );

    function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->addFieldsToTab('Root.Main', singleton('InternalExternalLink')->getCMSFields());

I understand you probably need to create the dataobject first, get the ID and then save to the Page object - can the CMS not do this scaffolding, create (or update) and save this related dataobject automatically like ModelAdmin does?

1
Are you trying to show and save all the fields of internalExternalLink in the page edit screen? - jberculo
yes, save the fields from the elated dataobject into the related dataobject - DaveO

1 Answers

0
votes

You should use a GridField for this which handles saving to the nested object. Checkout the relational handler module for a has_one relationship editor. You can also get it working without the module if you don't want to install another dependancy. Just create a new GridField instance and pass your has_one record as an DataList query.

http://addons.silverstripe.org/add-ons/simonwelsh/gridfieldrelationhandler