2012-07-10 72 views
-2

我基本上試圖通過返回我的項目和更新表的用戶和評論來擴展我的查詢的深度。cakephp完整查找/讀取深度

網站訪問者可以查看項目,該項目有許多更新下面列出。

用戶可以在下面的初始項目和更新中發表評論,每個更新和項目都由任何用戶提交。

我已經建立了下面的關係,但這些可能是錯誤的:

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 

我ProjectController.php的觀點如下:

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

但這僅導出包含數組:

Project 
    User  (belonging to Project) 
    Comments (belonging to Project) 
    Updates  (belonging to Project) 

但我想這個完整的結果,包含意見對一切克和用戶對於這些意見:

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) 

在數據庫中,註釋由一個ID(USER_ID)並列到用戶幷包含有關用戶的比沒有更多的細節。

回答

5

在撥打read()之前,您是否嘗試過撥打$this->Project->recursive

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 

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