How do I display the record count of a related model with CakePHP? -
i have 2 models. lets "posts" , "comments". in admin view posts, want display how many comments on post. confused on put code. in controller or view? in controller.
another option cache count. approach, you'd add field comment_count
posts
table, modify comment
model's belongsto
association this:
class comment extends appmodel { var $belongsto = array( 'post' => array( 'countercache' => true ) ); }
anytime new comment
record created, comment_count
of associated post
record incremented, , decremented anytime associated comment
deleted.
Comments
Post a Comment