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.

Data Model Questions /

Expiring a date-based object?


3 Posts   1329 Views


Community Member, 10 Posts

11 October 2010 at 11:26pm

Edited: 11/10/2010 11:27pm

I can't get my head round the following ... I hope someone can help :-)

I have an Event DataObject as below and want any events that have taken place not to display when I call the events stored in the database. Ideally, I want to automatically delete the event from the database at the end of the day on which it takes place.

I see the CMS Workflow module has an Expiry method but from what I can gather this only applies to Pages not objects.


class Event extends DataObject
   static $db = array (
      'EventName' => 'Text',
      'Description' => 'Text',
      'Date' => 'Date',
      'Time' => 'Text',
      'Venue' => 'Text',
      'ContactNumber' => 'Text'


class EventPage_Controller extends Page_Controller
   function Event()
      return DataObject::get(
         'Date ASC',

Many thanks in advance!


Community Member, 94 Posts

12 October 2010 at 7:37am


i guess you can do this by just checking if date has passed in the query which will be generated by silverstripe through the DataObject get method.

something like:

return DataObject::get('Event', "Date > NOW()", 'Date DESC');


Community Member, 10 Posts

12 October 2010 at 9:47pm

Thanks bart. It works a treat!
I think I was over-thinking it and expecting it to be more complicated! :-)