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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

how to prevent certain records from deletion?

Go to End

2 Posts   593 Views


Community Member, 48 Posts

30 September 2012 at 4:23am

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,


Forum Moderator, 5523 Posts

30 September 2012 at 5:54pm

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().