Jump to:

23493 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » how to prevent certain records from deletion?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 290 Views
  • woodb2
    Community Member
    48 Posts

    how to prevent certain records from deletion? Link to this post

    I'm working in ModelAdmin with a couple of DataObjects, Project and Deliverables (Projects have many deliverables). I'm managing the Deliverables from inside Project with a DataObjectManager. Each Deliverables has a hidden field nondelete that if set to yes (1) the user should not be able to delete the record.

    I thought that in my Deliveable class I could just set something like:

       function canDelete() {
          if($this->nondelete == 1) {
          return false;

    I'm not sure how to prevent certain records from being deleted. I also tried a few things using OnBeforeDelete() in Deliverables, but had no luck with that either.

    Any help would be appreciated,

  • Willr
    Forum Moderator
    5508 Posts

    Re: how to prevent certain records from deletion? Link to this post

    Does that canDelete code not work? I would assume it would, though if you've logged in as an administrator it probably overrides all permission checking. Perhaps structure it so the CMS users are not full admins but another user group which will then check against canDelete().

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.