假设我有一个模型Post
和一个Comment
相关的模型如下:
Post hasMany Comment
Comment belongsTo Post
如何使用它find('all')
来检索每一个Post
与其相关联的最新版本Comment
?
我尝试将hasOne
关系定义Post
为:
var $hasOne = array('LatestComment' => array('className' => 'Comment', 'order' => 'LatestComment.created DESC'));
但是,当我执行 a 时Post->find('all')
,它每隔Post
多次返回一次,每次返回一次Comment
,并LatestComment
设置为不同的Comments
。