Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » default_sort using secondary table

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

Page: 1
Go to End
Author Topic: 1137 Views
  • Nicolaas
    Forum Moderator
    213 Posts

    default_sort using secondary table Link to this post


    I have a table called "options" and a table called "option groups". I want to sort the options by group and then by option. For the sorting, I have added the Sort field to both tables...

    I would like to sort Options like this:

    static $default_sort = "OptionGroup.Sort ASC, Option.Sort ASC";

    I added the following function to Option:

    class Option extends DataObject {
       static $default_sort = "OptionGroup.Sort ASC, Option.Sort ASC";
       public function extendedSQL($filter = "", $sort = "", $limit = "", $join = "", $having = ""){
          $join .= " LEFT JOIN \"OptionGroup\" ON \"OptionGroup\".\"ID\" = \"Option\".\"OptionGroupID\"";
          return parent::extendedSQL($filter, $sort, $limit, $join, $having);

    However, it does not work...

  • swaiba
    Forum Moderator
    1792 Posts

    Re: default_sort using secondary table Link to this post

    does this thread help? (towards the end some is doing similar i think, sort based on join)

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.