It’s clear - to make null values on top can be used that SQL:

ORDER BY date_end IS NULL DESC, date_end DESC

and here is how to pas that SQL order in CakePHP:

array('date_end' => 'IS NULL DESC', 'Model.date_end' => 'DESC')

Here is few things you should keep in mind:
1) if you just write date_end IS NULL as string, CakePHP will fail with error ‘date_end IS NULL’ column not found, thats why we have that array to pass order fields;
2) the second parameter is Model.date_end, because is you make it just date_end CakePHP will ignore it because date_end is already in array of sorted fields.

That’s all, happy coding.

Posted by Rostislav Palivoda, filed under PHP. Date: November 22, 2008, 2:11 pm |

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.