Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Delete DataObjectManager Items in Control

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 651 Views
  • DeklinKelly
    Community Member
    197 Posts

    Delete DataObjectManager Items in Control Link to this post

    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); ?

  • UncleCheese
    4085 Posts

    Re: Delete DataObjectManager Items in Control Link to this post

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

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.