7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Delete DataObjectManager Items in Control
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 541 Views |
-
Delete DataObjectManager Items in Control

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); ?
}
} -
Re: Delete DataObjectManager Items in Control

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())");
| 541 Views | ||
|
Page:
1
|
Go to Top |

