Jump to:

3459 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » trying to save custom data to image-table; almost there

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 905 Views
  • theAlien
    Community Member
    131 Posts

    trying to save custom data to image-table; almost there Link to this post


    I'm trying to save custom data to the image-table.
    I thought it should be possible with $casting, but it appears not...

    With $this->Description the table-column has value NULL.
    If I'm hardcoding some value instead (like 'MyTestValue'), the tablecolumn will get the value 'MyTestValue'.

    Since the hardcoding works, everything else seems right.
    So it has something to do with the $casting and my calling of it.

    Can someone shed a light on it?
    Code is below.

    Thanks a lot!

    class ImagePage extends Page {

       public static $has_one = array(
          'testImage' => 'Image'
       static $casting = array(
          "Description"   => "Varchar",

       public function getCMSFields() {
          $fields = parent::getCMSFields();

          $testImage = new ImageField('testImage','Image');
          $description =    new TextField('Description','Description');
          $fields->addFieldsToTab("Root.Content.Image", array(

          return $fields;

       public function onBeforeWrite() {

          $myImage = DataObject::get_by_id('Image',$this->testImageID);

             $myImage->Description = $this->Description;

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.