I saw your other post CakePHP Elements not updating table, so I sort of have an idea of your situation. It seems you are representing comments with your Post model.
You want to query data from your Post model, in your UploadsController, correct?
If your comments table is named comments
, you need to ensure it is associated to your Post model. Cake automatically associates Models and database tables if they follow Cake's naming conventions. But if they are in fact different, you can specify a custom database table for your Post model:
<?php
class Post extends AppModel {
var $useTable = "comments" /*Or whatever you named your comments table*/
...
}
?>
You also have to ensure the model associations are set up between Post and Upload:
Post belongsTo Upload
Upload hasMany Post
I noticed you have:
Post belongsTo Upload
Upload hasAndBelongsToMany Post
Is there a reason why it is HABTM? HABTM implies that the same Post can belong to many different Uploads. hasMany implies that a Post can only belong to a single Upload.
Finally, now that the model associations are set up, you can access related models in a controller:
<?php
class UploadsController extends AppController {
...
function watch ($id = null) {
$this->Upload->id = $id;
$this->set('uploads', $this->Upload->read());
/* To get related comments (Posts) */
$related_comments = $this->Upload->Post->find('all', array(
'conditions' => array(
'Upload.id' => $id /* This condition makes it so only associated comments are found */
)
));
$this->set('comments', $related_comments);
}
...
}
?>