Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

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

trying to save custom data to image-table; almost there

Go to End



Community Member, 131 Posts

28 January 2010 at 5:25am

Edited: 28/01/2010 5:25am


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;