Jump to:

3375 Posts in 999 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » SS3.1 onBeforeWrite and new Object ID

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

Page: 1
Go to End
Author Topic: 188 Views
  • zenmonkey
    Avatar
    Community Member
    524 Posts

    SS3.1 onBeforeWrite and new Object ID Link to this post

    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

    188 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.