Jump to:

3462 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » augmentSQL seems to empty fields from object

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

Page: 1
Go to End
Author Topic: 148 Views
  • micschk
    Community Member
    19 Posts

    augmentSQL seems to empty fields from object Link to this post

    I'm developing a simple module to provide 'soft' scheduling of pages (Embargo & Expire, I'm aware this is also provided by the workflow module). For this I wrote a SiteTreeExtension which adds Embargo & Expiry as Datetimefields.

    I'm trying to implement augmentSQL on this in order to filter out pages that are under embargo/expiry. But any time I add an extra 'Where' clause to the augmentSQL method involving the Embargo or Expiry fields, the 'Embargo' and 'Expiry' fields of all resulting Pages appear unset. If I comment out the 'addWhere' lines, these fields load their data just fine.

    Am I missing something?

    class EmbargoExpirySchedulerExtension extends SiteTreeExtension {
       public static $db = array(
          'Embargo' => 'SS_Datetime',
          'Expiry' => 'SS_Datetime'


       function augmentSQL(SQLQuery &$query) {
          $myclass = $this->owner->className;
          if (is_subclass_of(Controller::curr(), 'ContentController')) { // on frontend
                   "\"{$myclass}\".\"Embargo\" IS NULL OR \"{$myclass}\".\"Embargo\" < NOW()",
                   "\"{$myclass}\".\"Expiry\" IS NULL OR \"{$myclass}\".\"Expiry\" > 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.