In my User model I have fields follower_count
and following_count
.
And for followers and following I have HABTM association in my User as defined below:
public $hasAndBelongsToMany=array(
'Following'=>array(
'className'=>'User',
'joinTable'=>'user_correlations',
'foreignKey'=>'correlated_id',
'associationForeignKey'=>'user_id',
'fields'=>'id,first_name,last_name,photo_dir,photo',
'order'=>'Rand()'
),
'Followers'=>array(
'className'=>'User',
'joinTable'=>'user_correlations',
'foreignKey'=>'user_id',
'associationForeignKey'=>'correlated_id',
'fields'=>'id,first_name,last_name,photo_dir,photo',
'order'=>'Rand()'
)
);
How can I find Followers count and Following count in this case?