Count With Join

Hello In need help with count my posts in begin of forum categories list

SELECT COUNT(id) FROM posts a INNER JOIN topics b ON a.tid = b.id WHERE b.fid=$fid this is the old code,

Can I do this count in my forum model by relations or better do it in controller and how it looks in yii style?

thanks!

Dear Friend

Let us consider an example.

Author and Posts.

Author has many posts.

relation.




public function relations()

	{

	

		return array(

			'posts' => array(self::HAS_MANY, 'Post', 'a_id'),

		);

	}



Now we listing aurhor names.

we can also the number of posts written by him like following.




$author:Author::model()->findByPk($id);

echo count($author->posts);



We can also finetune a bit.

We want to know how many posts the author written related to YII.




$author=Author::model()->findByPk($id);

echo count($author->posts(array(

   'condition'=>'title LIKE "%yii%"',


  )));



Regards.