我有这个结构和表格的树模型:
Rate:
id, model_name, object_id
1 , SocialPost, 12
public $belongsTo => array(
'SocialPost' => array(
'className' => 'Social.SocialPost',
'foreignKey' => 'object_id',
'conditions' => array(
'Rate.object_id = SocialPost.id',
),
)
)
社会邮报:id,file_id
public $hasOne = array(
'File' => array(
'className' => 'File',
'foreignKey' => false,
'conditions' => array(
'File.id = SocialPost.file_id',
),
),
);
文件:id,标题
所有树模型都作为可包含的
此代码在 SocialPostsController 中运行良好:
$posts = $this->SocialPost->find('all', array(
'limit' => 5,
'contain' => array(
'File'
)
));
输出: http: //pastie.org/private/9ixxufncwlr3tofgp8ozw
但是 RatesController 中的这段代码为所有 SocialPost 返回相同的文件:
$mostRated = $this->Rate->find('all', array(
'limit' => $count,
'contain' => array(
'SocialPost' => array(
'File'
)
)
));
输出: http: //pastie.org/private/lbqryo1gxgvxjb5omfwrw
这里有什么问题?