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.

Data Model Questions

SS3.1 onBeforeWrite and new Object ID




12 November 2013 at 7:55am Community Member, 528 Posts

Now that in 3.1 a new dataobject is given a temporary ID, I'm wondering how to do an onBeforeWrite check to craete a new folder. I had been using.

if($this->ID != 0 && $this->FolderID == 0) {
         $filter = URLSegmentFilter::create();
         $folderName = $filter->filter($this->Title);
         $folderExists = Folder::find_or_make('Products/'.$folderName.'/');
         $this->FolderID = $folderExists->ID;

But now since it's craeting an Object called New Object it creates one folder called new-object then matchas all subsequent new items to it. I'm using if($this->Title 1= "New Product") but that just seems like its going to be called on every save