【发布时间】:2013-04-25 12:37:36
【问题描述】:
我有 2 张桌子预订和消息,现在我想在收件箱中一次显示预订请求和消息。
$this->paginate = array(
'conditions' => $conditions,'limit' =>10,
'order'=>array('Booking.created'=>'DESC'));
$bookings = $this->paginate('Booking');
$this->paginate = array(
'conditions' => $conditions,'limit' =>10,
'order'=>array('MessageDetail.created'=>'DESC'));
$messages = $this->paginate('MessageDetail');
我已经合并了两个表数据( array_merge($bookings, $messages); ) 现在我想按日期(或任何条件)对它进行排序
Array
(
[0] => Array
(
[Booking] => Array
(
[id] => 4
[host_id] => 21
[place_id] => 10
[room_id] => 13
[user_id] => 12
[message_detail_id] => 16
[created] => 2013-04-23 14:44:03
[accept_date] =>
[cancel_date] =>
)
)
[1] => Array
(
[Booking] => Array
(
[id] => 3
[host_id] => 21
[place_id] => 10
[room_id] => 13
[user_id] => 12
[message_detail_id] => 13
[created] => 2013-04-15 14:10:59
[accept_date] => 2013-04-15 14:40:47
[cancel_date] =>
)
)
[2] => Array
(
[MessageDetail] => Array
(
[id] => 17
[message_id] => 2
[user_id] => 12
[sender_id] => 21
[unread] => 0
[created] => 2013-04-24 12:11:47
)
)
[3] => Array
(
[MessageDetail] => Array
(
[id] => 15
[message_id] => 2
[user_id] => 12
[sender_id] => 21
[booking_id] => 3
[unread] => 0
[created] => 2013-04-15 15:01:12
)
)
)
提前致谢。
【问题讨论】:
-
以上代码只对消息进行排序。不预订
-
请澄清 - 很难确定要问什么。
-
@YogeshSaroya 您在预订和消息之间有关联吗?听起来,这可能是您希望数据库为您做的事情,而不是在 PHP 中手动执行?
-
@SamDelaney 在之前的评论中所说的可能是要走的路。如果您发布原始查询以检索数据和模型之间的关系,那么有人可能会为您提供更多帮助。在问题中添加 sql 标签也可能有助于在这里吸引一些 sql 专家的注意。
标签: arrays cakephp cakephp-2.0