我有訂單模型,它通過字段user_id登錄到用戶模型。 現在我想爲每個用戶獲得1個OLDEST訂單。例如:模型組和訂單
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訂單總是在訂購之前完成。 如何強制find方法在創建字段之前按分組進行排序?
我試過了 - min_created字段是正確的(最早的日期),但訂單記錄是錯誤的(具有不同的創建日期) – user606521