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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Delete DataObjectManager Items in Control


Reply


2 Posts   708 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, 4096 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())");