Ar Model Search From Related Table With Multiselect Values


I have these models;

  • Post

  • Category

  • PostCategory

and the relation in Post is;

'postcategories' => array(self::HAS_MANY, 'PostCategory', 'postid', 'with'=>'category'),

In my search view file, I have multiselect input which allow to select multiply category to search posts that belongs to these category or categories.

My ‘search’ function in Post AR model class is;

public function search()


		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->with = array(



                // other criterias

                $criteria->compare('title', $this->title, true );

		$criteria->compare('', $this->postcategories, true );


		$config = array(


			'sort' => array(

				'defaultOrder' => array(

					'modificationdate' => CSort::SORT_DESC





		return new CActiveDataProvider($this, $config);


and controller action;

public function actionChanges( ) 


		$model=new Post('search');








When I click the search button just one selected value appears in the url so it cannot show other category posts in the grid.


I guess it must be like this,


Is there any other solution or what am I doing wrong?


Follow this forum post.

Oh, really thanks.