I have the following relationship:
Post hasMany Comment
Post belongsTo Category
Post HABTM Tag
I want to use the paginate method with those properties:
public $paginate = array(
'published',
'limit' => 3,
'fields' => array(
'Post.title',
'Post.date_published',
'Post.abstract',
'Post.slug',
'Category.value',
'Category.slug'
)
);
'published' is a customized find query, but that should not matter here. In addition to the infos about a Post and its Category (seen above), I would like to fetch the COUNT of Comments a post has, and the names of all Tags. I.e., I would like to be able to access the data on the View side in a convenient way such as $data['Post']['comment_count'] and $data['Post']['Tag'][0]['name'].
Is there a solution to this which is elegant enough? I know HABTM might be a bit complicated, but I don't even know how to fetch the Comments in the same query, even though it's only a hasMany relationship. Thank you.