2012-07-10 2 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) 

하지만 나는이 모든 결과에 모든 의견을 포함하고 싶습니다. g 그 의견에 대한 사용자 : 데이터베이스에서

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