Jump to:

3433 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » onBeforeDelete issues SS3

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

Page: 1
Go to End
Author Topic: 444 Views
  • zenmonkey
    Avatar
    Community Member
    527 Posts

    onBeforeDelete issues SS3 Link to this post

    I have a Page Type that automoatically creates a folder to save any images loaded to it. I've set up an onBeforeDelete to delete the folder if the page is deleted, however it throws an excpetion that I'm trying to delete an an Object without an ID. I'm sure its in the onBeforeDelete becaise if I remove it the page deletes fine.

       function onBeforeDelete() {
       
          if($this->FolderID != 0){
             $folder = $this->Folder();
             
             if($folder) {
                $folder->delete();   
             }
          }
          parent::onBeforeDelete();
       }

    Any ideas?

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: onBeforeDelete issues SS3 Link to this post

    Bump! Still haven't figured this out. the $folder->delete() throws an error that i'm trying to delete a dataobject without an ID

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: onBeforeDelete issues SS3 Link to this post

    After some digging I've realized onBeforeWrite fires on Unpublish, so the Dataobejct is deleted then and not when the page is deleted

    444 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.