class Image extends DataMapper { ... function delete($object = '', $related_field = '') { // capture any important information here (id, etc) // delete the item $success = parent::delete($object, $related_field; // if the item was successfully deleted, then cleanup if($success && empty($object) && !is_array($object)) { // do the cleanup } } ... }