phpyiimodelcgridview

Yii: CgridView through several relation


I follow this guide to create a cgridview allowing to searching and sorting related model: http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/

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 (install.no... 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(
    'id'=>'t-license-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
            array(            
              'name'=>'siteId_search',
              'value'=>'$data->install->node->f_site_id',
              'header'=>'Site',
            ),
            array(            
              'name'=>'installId_search',
              'value'=>'$data->install->f_install_id',
              'header'=>'installId',
            ),
            [...]
    ),
));

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(
            'criteria'=>$criteria,
    ));
}

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


Solution

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

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

    by

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

    in my search()