Search related table?


(Chris De Kok) #1

How Do I perform a search on a related table? Something like:


$criteria=new CDbCriteria;

                $criteria->with=array(

                    'pages.content',

                );

                $criteria->condition = 'pages.content LIKE :keyword';

                $criteria->params = array(':keyword' => '%'.$q.'%');


                $bookCount = Books::model()->count($criteria);

                $pagination = new CPagination($bookCount);

                $pagination->pageSize = 10;

                $pagination->applyLimit($criteria);


                $books = Books::model()->findAll($criteria);

Does not work :(


(Vamphouse) #2

try:


	$criteria->with=array(

		'pages'=>array(

			'condition' => 'content LIKE :keyword',

		),

	);


(Nemoneel) #3

Can you post your search action controller