I am trying get all commments relateed to my current post, I am doing it as following:
$this->Post->Comment->find('all', array('conditions' => array('post_id' => $id)));
but in my opinion, it is a little uncomfortably. Why I should give post_id? Isn’t it obvious that I want Comment related to current Post?
If you do not specify the conditions (
$this->Post->Comment->find('all');) you will get all comments with their related records.It is advisable to specify the model name in the conditions:
$this->Post->Comment->find('all', array('conditions' => array('Comment.post_id' => $id)));. This way you will get the comments for the specific post and all associated (to the comments) data.If you do not like
'conditions'array you need to specify id explicitly as Leo mentioned (from Post controller):This way you will get the post and all data associated to it.
Notice that in the first method you retrieve all data associated to the comments and in the second method – all data associated to the post.