user3166173 user3166173 - 1 year ago 101
PHP Question

Yii: CgridView through several relation

I follow this guide to create a cgridview allowing to searching and sorting related model:

Here are my relations:
license BELONGS_TO install
install BELONGS_TO node

I can by this way create a CGridview with any field of my license and install models. However, I can have fields of the node model, But I have the following error when searching on it:

CDbCommand failed to execute the SQL statement: SQLSTATE[42P01]: Undefined table: 7 ERROR: invalid reference to FROM-clause entry for table node
LINE 1: ...."f_product_id"="product"."f_product_id") WHERE (
HINT: There is an existing input for table node but it can't be referenced in this query

I don't understand, my table node is linked in my search fuction.

Here is my CGridview on model license:

$this->widget('zii.widgets.grid.CGridView', array(

And my my license model:

public function search()
// Warning: Please modify the following code to remove attributes that
// should not be searched.

$criteria=new CDbCriteria;

$criteria->with=array('install.node', 'install.product');

$criteria->compare( 'install.node.f_site_id', $this->siteId_search, true );

$criteria->compare( 'install.f_install_id', $this->installId_search, true );


return new CActiveDataProvider('t_licence', array(

Any Idea? You can see that my search function also call table install.product, I have the same problem on it.

Answer Source

Solved! It was a silly thing, I just had to change this

$criteria->compare( 'install.node.f_site_id', $this->siteId_search, true );


$criteria->compare( 'node.f_site_id', $this->siteId_search, true );

in my search()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download