我有订单模型,它通过字段 user_id 属于用户模型。现在我想为每个用户获得 1 个最旧的订单。例如:
id = 0, user_id = 1, created = 2012-10-10 20:36:42
id = 1, user_id = 1, created = 2012-10-10 19:36:42
id = 2, user_id = 1, created = 2012-10-10 21:36:42
id = 3, user_id = 2, created = 2012-10-10 22:36:42
id = 4, user_id = 2, created = 2012-10-10 21:36:42
id = 5, user_id = 2, created = 2012-10-10 23:36:42
所以结果应该是:
id = 1, user_id = 1, created = 2012-10-10 19:36:42
id = 4, user_id = 2, created = 2012-10-10 21:36:42
我现在使用以下查找选项:
array(
'group' => 'user_id',
'order' => array('MIN(created) DESC'),
)
并尝试过'order' => array('created DESC')
但它不起作用 - 似乎 GROUPING 订单总是在 ORDERING 之前完成。如何在分组之前强制 find 方法按创建的字段对记录进行排序?