Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » DataObject get return error when trying to SORT

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

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

Page: 1
Go to End
Author Topic: 2748 Views
  • Hammy
    Avatar
    Community Member
    49 Posts

    DataObject get return error when trying to SORT Link to this post

    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?

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: DataObject get return error when trying to SORT Link to this post

    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.

  • Hammy
    Avatar
    Community Member
    49 Posts

    Re: DataObject get return error when trying to SORT Link to this post

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

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