I'm basically trying to extend the depth of my query by returning the Users and Comments for both my Project and Update tables.
Site visitors can view a Project, which has many Updates listed below it.
Users can leave comments on both the initial Project AND the Updates below, and each update and project is submitted by any users.
I have the following relationships set up, but these could be wrong:
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
The view in my ProjectController.php is as follows:
public function view($id = null, $slug = null) {
$this->Project->id = $id;
$this->set('Projects', $this->Project->read());
}
But this only exports an array containing:
Project
User (belonging to Project)
Comments (belonging to Project)
Updates (belonging to Project)
But I would like this full result, containing the comments to everything and the users for those comments:
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)
In the database, comments are tied to users by one ID (user_id) and contain no more details about the user than that.