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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

automated deletion

Go to End

3 Posts   774 Views


Community Member, 131 Posts

29 January 2010 at 4:30am

I have an ImageDataObject with a 1- relation to Image.
If the Image is deleted (fx in Files and Images), the related ImageDataObject isn't necessary anymore.
So I'm trying to automate the deletion of the ImageDataObject, but I'm kind of stuck...

This is what I have right now:

class MyImageDecorator extends DataObjectDecorator {


	public function onBeforeDelete() {
		$query = new SQLQuery('*', array('ImageDataObject'), $ImageID = $this->ID);
		$query->delete = true;

However, this prevents the deletion of the image in Files and Images.
Can someone see what I'm doing wrong and/or give me some advice on automating it?


Community Member, 89 Posts

1 February 2010 at 9:51am

You apply that decorator to the File, right? Then I think because it's a decorator, you should use $this->owner->ID instead of $this->ID. Hmm what do you think about using onAfterDelete instead of before? This would be better in case the Image does not get removed for some odd reason and you want to keep your ImageDataObject after all. Also, when decorating, don't use parent call - you are not extending the object in question, so that's not needed.



Community Member, 712 Posts

1 February 2010 at 10:21am

Also the where statement is malformed:

$query = new SQLQuery('*', array('ImageDataObject'), $ImageID = $this->ID);

should probably be:

$query = new SQLQuery('*', array('ImageDataObject'), "ImageID = {$this->owner->ID}");