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.

Archive /

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

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

DataObject get return error when trying to SORT


Reply


3 Posts   2800 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...