Hi how do I group by and order by a datetime field with CakePHP?
A:
Did you already make an attempt and did it fail?
I don't have a CakePHP installation around to verify, but my first guess would be to state in the controller:
$this->Model->find("all", array('order'=>'Model.datetimeFieldName'));
I'd expect Cake to handle the ordering.
Brelsnok
2010-02-05 09:32:12
A:
An even better way to do this is to specify the order in the Model.
http://book.cakephp.org/view/440/order
You can still of course override that in the controller later.
PawelMysior
2010-02-05 10:52:17
+5
A:
$this->Post->find('all', array(
'order' => array('Post.date' => 'DESC'),
'group' => 'Post.date'
));
TiuTalk
2010-02-05 10:57:41