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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Images In DataObjectManager not deleting!


7 Posts   815 Views


19 August 2011 at 4:18am Community Member, 11 Posts

Hi there,

I've knocked up a banner management area using DataObjectManager within SiteConfig (with various hints and tips from this forum) and it works perfectly, or should I say WORKED perfectly until today during some testing. When I go to delete an image it 'deletes' fine from within the DataObjectManager but when I browse to the folder the images are stored in, they are still there. I can only remove them by either manually deleting them from the folder or from within 'Files & Images'.

As adding a DataObjectManager in SiteConfig has proven troublesome, I thought it might be an issue to do with that so I redid the code as a simple BannerPage but the problem still exists.

Here is the code - please help as this is driving me nuts!

<-- Banner2.php -->


class BannerImage2 extends DataObject
   static $db = array (

   static $has_one = array (
      'myImage2' => 'Image',
      'BannerPage' => 'BannerPage'

   public function getCMSFields_forPopup()
         $upload = new ImageUploadField('myImage2', 'Upload Banner Image');
         $upload->uploadFolder = 'BannerImages2';
         return new FieldSet($upload);

   public function getThumb()
      return $this->myImage2()->setWidth(400);
      return '(No Image)';

<-- BannerPage.php -->


class BannerPage extends Page {

static $has_many = array(
         'Images' => 'BannerImage2'

public function getCMSFields() {

   $fields = parent::getCMSFields();
   $fields->addFieldsToTab("Root.Content.Main", new DataObjectManager(
         array('Thumbs'=>'Upload Image'),
   return $fields;

class BannerPage_Controller extends Page_Controller {



19 August 2011 at 5:48pm Community Member, 11 Posts

Ok, I've checked PHPMyAdmin and adding an image via the DataObjectManager DOES add it into the database and by deleting the recorded in the DataObjectManager it DOES delete it from the database but for some reason it is not deleting the actual physical image!!


19 August 2011 at 6:05pm Community Member, 11 Posts

One last little note to help you all to help me, if you click on the record and then delete the image from within the popup, it does physically delete the image but then I am left with an empty record which I have to manually delete.

If I just delete the record on its own, it seems to just remove the link to the image rather than the image itself.


20 August 2011 at 12:46am 4085 Posts

DataObjectManager doesn't manage objects that are related to those that it is managing. That wouldn't make any sense to cascade deletion down to the has_one relationships because if a file is used in multiple places, you'd break stuff! Cascading deletes are business logic, and should only be used when you know that a file will only ever be associated with a single record. For that reason, this is an elective option. You can use an onAfterDelete() hook to delete the associated file if you want.

Silverstripe tips, tutorials, screencasts, and more.


20 August 2011 at 1:39am Community Member, 11 Posts

Thanks for getting back to me UncleCheese. I think I understand what you mean but how would I go about using the onAfterDelete() hook?



20 August 2011 at 2:09am Community Member, 11 Posts

Figured it out! - Thanks Uncle Cheese! :-)


21 August 2012 at 3:47am Community Member, 60 Posts

can you share your code for the solution for onAfterDelete() hook thanks