Hi folks,
I'm trying to join a model through a hasmany association and then count the number of records. Basically I have users and projects. I want to display the number of associated projects on the user index action.
var $hasMany = array('Project' =>
array('className' => 'Project',
'conditions' => '',
'order' => '',
'limit' => '',
'foreignKey' => 'user_id',
'dependent' => true,
'exclusive' => false,
'finderQuery' => '',
'fields' => '',
'offset' => '',
'counterQuery' => '',
'counterCache' => true
)
);
So I have joined to Project model on user_id and have set the counterCache to true. The question is how do I access this in the user index view?
I've tried
<?php echo $user['Project']['project_count']; ?>
and
<?php echo $user['User']['project_count']; ?>
Can someone help me?
Jonesy