我有兩種型號:事件和日期。一個事件有很多日期。我想按最近的日期排序。例如:Cakephp:按相關型號查找訂單
[0] => Array
(
[Event] => Array
(
[id] => 1
[name] => Event 1
)
[Date] => Array
(
[0] => Array
(
[id] => 1
[date] => 2015-02-05
[start_time] => 06:00:00
[end_time] => 17:00:00
[evento_id] => 1
)
[1] => Array
(
[id] => 2
[date] => 2015-02-06
[start_time] => 06:00:00
[end_time] => 17:00:00
[evento_id] => 1
)
)
)
[1] => Array
(
[Event] => Array
(
[id] => 2
[name] => Event 2
)
[Date] => Array
(
[0] => Array
(
[id] => 3
[date] => 2015-02-11
[start_time] => 06:00:00
[end_time] => 17:00:00
[event_id] => 2
)
)
)
[2] => Array
(
[Event] => Array
(
[id] => 3
[name] => Event 3
)
[Date] => Array
(
[0] => Array
(
[id] => 5
[date] => 2015-02-02
[start_time] => 06:00:00
[end_time] => 17:00:00
[event_id] => 3
)
[1] => Array
(
[id] => 6
[date] => 2015-02-03
[start_time] => 06:00:00
[end_time] => 17:00:00
[event_id] => 3
)
)
)
所以,我想要檢索的事件順序是:事件3,事件1,事件2。
這是我的我打電話find方法:
$this->Event->find('all', array('contain' => array('Date' => array('conditions' => array('Date.date >=' => date('Y-m-d'))))));
這是可能做到這一點與CakePHP的發現方法?謝謝。
這不是通過'find'但[哈希::排序(http://book.cakephp.org/2.0/en/core-utility-libraries /hash.html#Hash::sort)可以使用。例如:將您的'find'賦值給$ results然後'$ resultsort = Hash :: sort($ results,'{n} .Date。{n} .date','asc');' – AgRizzo 2015-02-06 11:58:15