【发布时间】:2016-02-24 17:33:09
【问题描述】:
我正在使用 cakephp 2 框架。
我有一个具有“hasmany”关系的模型“主题”:
public $hasMany=array(
'Messages' => array(
'className' => 'Messages',
'foreignKey'=>'id_topic',
'dependent'=>true,
),
);
在我的控制器中我这样做:
$this->paginate = array(
'Topic' => array(
'limit' => 10,
'recursive' => 2,
)
);
$entities = $this->paginate('Topic');
它工作得很好,但现在我想按最后一条消息的日期对我的主题进行排序,但我不知道如何。
类似:
$this->paginate = array(
'Topic' => array(
'limit' => 10,
'recursive' => 2,
'order'=>'Messages.created desc'
)
);
但我得到Column not found: 1054 Unknown column 'Messages.created' in 'order clause'
有什么想法吗?谢谢
【问题讨论】:
-
你试过这个
'order' => array('Messages.created' => 'desc')
标签: php cakephp cakephp-2.0 relationship