說我有一個模型Post
及相關作爲模型Comment
如下:獲取與CakePHP中
Post hasMany Comment
Comment belongsTo Post
如何使用find('all')
檢索每Post
與其相關的最新Comment
?
我曾嘗試在Post
定義爲hasOne
關係:
var $hasOne = array('LatestComment' => array('className' => 'Comment', 'order' => 'LatestComment.created DESC'));
但是當我做了Post->find('all')
它的每一個Post
多次返回,每各Comment
一次,LatestComment
設置爲不同的Comments
。
可能與我的問題有關:http://stackoverflow.com/questions/8707048/last-x-blog-entries-but-only-once-per-user/11933591#11933591 – mark 2012-08-25 21:08:45