1
votes

Im using the Link class in an extended DataObject as $has_one. But when i save my Object the Link value is lost.

<?php 

class Teaser extends DataObject {

    private static $db = array (
        'Title' => 'Varchar',
        'Description' => 'HTMLText'
    );

    private static $has_one = array (
        'Photo' => 'Image',
        'MyLink' => 'Link'
    );

    private static $many_many = array(
        'Tags' => 'Tag'
    );

    private static $summary_fields = array (
        // ...
    );

    public function getCMSFields() {
        $fields = FieldList::create(
            TextField::create('Title'),
            $tags = TagField::create('Tags','Tags',Tag::get(),$this->Tags()),
            HTMLEditorField::create('Description', 'Beschreibung'),
            LinkField::create('MyLink', 'Weiterleitung', $this->MyLink()),
            $uploader = UploadField::create('Photo')
        );

        // ...

        return $fields;
    }
}

i tried the example in a Page and it works but in the DataObject i cant save the value.

https://github.com/sheadawson/silverstripe-linkable

1

1 Answers

2
votes

As stated in the Example you need to add ID to the field title. As it's a $has_one relation, MyLink will be saved as MyLinkID in database.

LinkField::create('MyLinkID', 'Weiterleitung', $this->MyLink())

should do the trick.