Yii Framework Forum: Search related table? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Search related table? Rate Topic: -----

#1 User is offline   mech7 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 220
  • Joined: 26-March 09

Posted 15 March 2010 - 01:51 AM

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 :(
0

#2 User is offline   vamp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 181
  • Joined: 30-January 09

Posted 15 March 2010 - 03:23 AM

View Postmech7, on 15 March 2010 - 01:51 AM, said:

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 :(



try:
	$criteria->with=array(
		'pages'=>array(
			'condition' => 'content LIKE :keyword',
		),
	);

-Posted Image-
Thanks, you make me stronger!
0

#3 User is offline   nemo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 24-February 10

Posted 15 March 2010 - 07:56 AM

View Postmech7, on 15 March 2010 - 01:51 AM, said:

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 :(


Can you post your search action controller
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users