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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

default_sort using secondary table

Go to End

2 Posts   1717 Views


Forum Moderator, 224 Posts

7 February 2011 at 3:53pm


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...


Forum Moderator, 1899 Posts

12 February 2011 at 1:01am

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