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   658 Views

Avatar
DeklinKelly

18 August 2010 at 10:37am Community Member, 197 Posts

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

18 August 2010 at 12:26pm 4085 Posts

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())");