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:

Archive /

Our old forums are still available as a read-only archive.

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

DataObject get return error when trying to SORT


Go to End


3 Posts   3237 Views

Avatar
Hammy

Community Member, 49 Posts

30 October 2008 at 9:44pm

This is likely to be a simple error on my part but I've been trying to sort a dataobject (using CategoryPage's Title column) alphabetically using the following:

	function TopCategories() {
		$filter = 'isTopCategory = 1';
		$sort = 'Title DESC';
		$num=10;
		$categories = DataObject::get('CategoryPage',$filter,$sort,'',$num);
		return $categories;
	}

But when ever i use a sort statement I get the following error:

FATAL ERROR: DATABASE ERROR: .... Column 'Title' in order clause is ambiguous ...

I've also tried the following:

	function TopCategories() {
		$filter = 'isTopCategory = 1';
		$sort = "'CategoryPage'.Title DESC";
		$num=10;
		$categories = DataObject::get('CategoryPage',$filter,$sort,'',$num);
		return $categories;
	}

but again this returns an error:


FATAL ERROR: DATABASE ERROR: ... You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.Title DESC LIMIT 10' at line 1

Can anyone help with this issue?

Avatar
ajshort

Community Member, 244 Posts

31 October 2008 at 12:56am

Hey Hammy,

I think your problem is the fact that you are redeclaring the Title field on your CategoryPage class. Does your CategoryPage::$db, or Page::$db contains something like

'Title' => 'Text'

If so, you should remove that line - as it would cause ambiguous title field errors - if you define it on a parent class (Title is defined on SiteTree) it is automatically added.

Avatar
Hammy

Community Member, 49 Posts

31 October 2008 at 9:27pm

Awesome - looks like that fixed the issue. Thanks for your help...