请问怎样用CDbCriteria来实现关联查询?

Post表里的字段:ID,title,body

PostCategory表里的字段:postID, categoryID

Category表里的字段:ID,categoryName

Post模型里:

	public function relations()


	{


		return array(


			'categories'=>array(self::MANY_MANY, 'Category', 'PostCategory(postID, categoryID)'),


		);


	}

控制器里:

	public function actionList()


	{


		$criteria=new CDbCriteria;





		$pages=new CPagination(Post::model()->count($criteria));


		$pages->pageSize=self::PAGE_SIZE;


		$pages->applyLimit($criteria);


		$postList=Post::model()->with('categoryies')->findAll($criteria);





		$this->render('list',array(


			'postList'=>$postList,


			'pages'=>$pages,


		));


	}

现在控制器里的actionList方法是显示所有文章,如果我想显示categoryID=1的文章,请问怎样做呢?



<?php


$criteria->condition = "categoryID = 1";


?>


Quote

<?php

$criteria->condition = "categoryID = 1";

?>

这样不行

CDbCommand 无法执行 SQL 语句: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'categoryID' in 'where clause'

Post表里没有categoryID这个字段

解决了,参照yii blog里的tag的实现方法