I have a DataObject
with a default sort:
class Author extends DataObject {
private static $db = array('Name' => 'Varchar');
private static $default_sort = 'Name ASC';
}
I want to Author::get()
the data but with no sort.
so given...
Author::create(array('Name' => 'DEF'))->write();
Author::create(array('Name' => 'ABC'))->write();
This would output ABC then DEF using the sort, but if the sort was cleared I'd expect DEF then ABC.
I've tried Author::get()->sort('')
and Author::get()->sort(null)
but both return ABC then DEF again.
Note The reason I'm asking is that I have a complex query (using joins) where this is causing an issue and I'm getting an error with it if I try and set the sort too.
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 'ORDER BY "_SortColumn0" ASC' at line 1
So the solution, and what I'd like to know anyway, is how to clear the default sort for the specific Author::get()
while keeping the existing default sort on the DataObject
?
I think the only way to unset the sort would be to manipulate the DataQuery
that underpins the DataList
which is returned when running Author::get()
.
$dq = Author::get()->dataQuery();
$dq->sort(null, null, true);
$authors = Author::get()->setDataQuery($dq);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With