Yii Framework Forum: Problem With Gridview Search Filters - Yii Framework Forum

Jump to content

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

Problem With Gridview Search Filters Rate Topic: -----

#1 User is offline   Jeffrico El Exotico 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 16-January 13

Posted 20 January 2013 - 11:59 AM

Hi all,

I'm trying to incorporate data from This tutorial in my own application.

I'm able to display the data, but am struggling, as I am consistently getting apparent sql errors when trying to search.

Now, I have tree tables

Person -> Junior -> Assignment

and related models

In person is a name (varchar) which I want to have searchable in assignment gridview.

I have

    public $last_name; 


In rules

  array('x, y, last_name ', 'safe', 'on' => 'search'),


In criteria

$criteria->with = array('junior', 'junior.person');
$criteria->compare('junior.person.name_last', $this->last_name);



Whenever I try to search on name, I get:

<p>CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'junior.person.name_last' in 'where clause'. The SQL statement executed was: SELECT COUNT(DISTINCT `t`.`id`) FROM `assignment` `t`  LEFT OUTER JOIN `junior` `junior` ON (`t`.`junior`=`junior`.`id`)  LEFT OUTER JOIN `person` `person` ON (`junior`.`id`=`person`.`id`)  WHERE (assignmentJunior.name.name_last=:ycp0) (/var/www/html/juniordb/yii/framework/db/CDbCommand.php:528)</p><pre>#0 /var/www/html/juniordb/yii/framework/db/CDbCommand.php(425): CDbCommand->queryInternal('fetchColumn', 0, Array)
#1 /var/www/html/juniordb/yii/framework/db/ar/CActiveFinder.php(728): CDbCommand->queryScalar()
#2 /var/www/html/juniordb/yii/framework/db/ar/CActiveFinder.php(155): CJoinElement->count(Object(CDbCriteria))
#3 /var/www/html/juniordb/yii/framework/db/ar/CActiveRecord.php(1544): CActiveFinder->count(Object(CDbCriteria))
#4 /var/www/html/juniordb/yii/framework/web/CActiveDataProvider.php(179): CActiveRecord->count(Object(CDbCriteria))
#5 /var/www/html/juniordb/yii/framework/web/CDataProvider.php(193): CActiveDataProvider->calculateTotalItemCount()
#6 /var/www/html/juniordb/yii/framework/web/CActiveDataProvider.php(129): CDataProvider->getTotalItemCount()
#7 /var/www/html/juniordb/yii/framework/web/CDataProvider.php(137): CActiveDataProvider->fetchData()
#8 /var/www/html/juniordb/yii/framework/zii/widgets/CBaseListView.php(108): CDataProvider->getData()
#9 /var/www/html/juniordb/yii/framework/zii/widgets/grid/CGridView.php(289): CBaseListView->init()
#10 /var/www/html/juniordb/yii/framework/web/CBaseController.php(148): CGridView->init()
#11 /var/www/html/juniordb/yii/framework/web/CBaseController.php(173): CBaseController->createWidget('zii.widgets.gri...', Array)
#12 /var/www/html/juniordb/protected/views/assignment/admin.php(42): CBaseController->widget('zii.widgets.gri...', Array)
#13 /var/www/html/juniordb/yii/framework/web/CBaseController.php(127): require('/var/www/html/j...')
#14 /var/www/html/juniordb/yii/framework/web/CBaseController.php(96): CBaseController->renderInternal('/var/www/html/j...', Array, true)
#15 /var/www/html/juniordb/yii/framework/web/CController.php(870): CBaseController->renderFile('/var/www/html/j...', Array, true)
#16 /var/www/html/juniordb/yii/framework/web/CController.php(783): CController->renderPartial('admin', Array, true)
#17 /var/www/html/juniordb/protected/controllers/AssignmentController.php(73): CController->render('admin', Array)
#18 /var/www/html/juniordb/yii/framework/web/actions/CInlineAction.php(50): AssignmentController->actionAdmin()
#19 /var/www/html/juniordb/yii/framework/web/CController.php(309): CInlineAction->runWithParams(Array)
#20 /var/www/html/juniordb/yii/framework/web/CController.php(287): CController->runAction(Object(CInlineAction))
#21 /var/www/html/juniordb/yii/framework/web/CController.php(266): CController->runActionWithFilters(Object(CInlineAction), Array)
#22 /var/www/html/juniordb/yii/framework/web/CWebApplication.php(283): CController->run('admin')
#23 /var/www/html/juniordb/yii/framework/web/CWebApplication.php(142): CWebApplication->runController('assignment/admi...')
#24 /var/www/html/juniordb/yii/framework/base/CApplication.php(162): CWebApplication->processRequest()
#25 /var/www/html/juniordb/index.php(16): CApplication->run()
#26 {main}</pre>


Please Help!
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,082
  • Joined: 16-February 11
  • Location:Japan

Posted 20 January 2013 - 12:07 PM

Hi Jeffrico,

Try this:
$criteria->with = array('junior', 'junior.person');
$criteria->compare('person.name_last', $this->last_name);


In the process of making SQL, 'junior.person' related AR object is translated to a joined table whose alias is 'person'.
0

#3 User is offline   Jeffrico El Exotico 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 16-January 13

Posted 20 January 2013 - 01:14 PM

Thanks, Perfect!
Spend forever looking for this...
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