Ar Model Search From Related Table With Multiselect Values

Hi,

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(

			'postcategories'

		);


                // other criterias

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

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

		

		$config = array(

			'criteria'=>$criteria,

			'sort' => array(

				'defaultOrder' => array(

					'modificationdate' => CSort::SORT_DESC

				),

			),

		);

		

		return new CActiveDataProvider($this, $config);

}

and controller action;


public function actionChanges( ) 

{

		$model=new Post('search');

		$model->unsetAttributes();

		if(isset($_GET['Post']))

			$model->attributes=$_GET['Post'];


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

				'model'=>$model,

		));

}

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

index.php?r=posts/changes&Post[title]=blabla&Post[postcategories]=10

I guess it must be like this,

index.php?r=posts/changes&Post[title]=blabla&Post[postcategories][]=10&Post[postcategories][]=11&Post[postcategories][]=16

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

Thanks

Follow this forum post.

Oh, really thanks.