cakephp完全查找/读取深度

Tim*_*Tim -2 php cakephp cakephp-model

我基本上试图通过返回Project和Update表的Users和Comments来扩展查询的深度.

网站访问者可以查看项目,该项目下面列出了许多更新.

用户可以在下面的初始项目和更新中留下评论,每个更新和项目都由任何用户提交.

我设置了以下关系,但这些可能是错误的:

Project.php (Model)
    belongsTo           - User
    hasMany             - Update, Comment

Update.php (Model)
    belongsTo           - Project, User
    hasMany             - Comment

Comment.php (Model)
    belongsTo           - Project, Update
    hasAndBelongsToMany - User

User.php (Model)
    hasMany             - Project, Update, Comment
Run Code Online (Sandbox Code Playgroud)

ProjectController.php中的视图如下:

public function view($id = null, $slug = null) {
    $this->Project->id = $id;
    $this->set('Projects', $this->Project->read());
}
Run Code Online (Sandbox Code Playgroud)

但这只导出一个包含以下内容的数组

Project
    User        (belonging to Project)
    Comments    (belonging to Project)
    Updates     (belonging to Project)
Run Code Online (Sandbox Code Playgroud)

但我想要这个完整的结果,包含对所有内容和用户的评论:

Project
    User        (belonging to Project)
    Comments    (belonging to Project)
        User        (belonging to each Comment)
    Updates     (belonging to Project)
        User        (belonging to Update)
        Comments    (belonging to Update)
            User        (belonging to each Update Comment)
Run Code Online (Sandbox Code Playgroud)

在数据库中,注释通过一个ID(user_id)与用户绑定,并且不包含有关用户的详细信息.

Jay*_*Jay 5

$this->Project->recursive打电话之前尝试过切换read()吗?

Depth   Description
-1      Cake fetches Group data only, no joins.
0       Cake fetches Group data and its domain
1       Cake fetches a Group, its domain and its associated Users
2       Cake fetches a Group, its domain, its associated Users, and the Users' associated Articles
Run Code Online (Sandbox Code Playgroud)

http://book.cakephp.org/1.3/view/1063/recursive