Hi,
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(
$testImage,
$description,
));
return $fields;
}
public function onBeforeWrite() {
$myImage = DataObject::get_by_id('Image',$this->testImageID);
if($myImage){
$myImage->Description = $this->Description;
$myImage->write();
}
parent::onBeforeWrite();
}
...