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:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Delete DataObjectManager Items in Control


Go to End


2 Posts   876 Views

Avatar
DeklinKelly

Community Member, 197 Posts

18 August 2010 at 10:37am

I want to delete all items with a 'Date' older than today.


	public function DeleteOldFeaturedAuthorScheduleItems () {
	 $o =  DataObject::get('FeaturedAuthorScheduleItem', "`Date` < '".date('Y-m-d')."'");
	   if(!empty($o))  {
		// Now how do I DELETE($o); ?
	   }
	}

Avatar
UncleCheese

Forum Moderator, 4102 Posts

18 August 2010 at 12:26pm

public function DeleteOldFeaturedAuthorScheduleItems () {
$o = DataObject::get('FeaturedAuthorScheduleItem', "`Date` < DATE(NOW())");
foreach($o as $a) $a->delete();
}

or more simply:

DB::query("DELETE FROM FeatureAuthorScheduleItem WHERE Date < DATE(NOW())");