17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2493 Views |
-
DataObject get return error when trying to SORT

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?
-
Re: DataObject get return error when trying to SORT

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.
-
Re: DataObject get return error when trying to SORT

31 October 2008 at 9:27pm
Awesome - looks like that fixed the issue. Thanks for your help...
| 2493 Views | ||
|
Page:
1
|
Go to Top |


