21475 Posts in 5781 Topics by 2620 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 405 Views |
-
automated deletion

29 January 2010 at 4:30am
Hi,
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;
$query->execute();
parent::onBeforeDelete();
}
}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? -
Re: automated deletion

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.
cheers,
mat -
Re: automated deletion

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}");
| 405 Views | ||
|
Page:
1
|
Go to Top |


