using relations with CGridView

Hi,

I’ll describe the problom as clearly as I can.

I have activeDataProvider:


$dataProvider=new CActiveDataProvider('Menu', array(

    'criteria'=>array(         

       'with' => array('roles'),

    ),

));



then I’am using CGridView with checkbox:


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

'id'=>'menu-grid',

'selectableRows' => 2,

'dataProvider'=>$dataProvider,

'columns'=>array(

        'id',

        'title',

         array(

            'class'    => 'SCheckboxColumn',

            'header'   => 'View',

            'name'     => 'Roles[Actions][can_view]',

            'id'       => 'roles_action_can_view',

             'value'    => '$data->id',

            'checkBoxHtmlOptions' =>

                array('checked' => $data->roles->can_view,),

        ),

    ),

));



Then in Menu Model relations:


return array(

        'roles' => array(self::HAS_MANY, 'Rolesmenus', 'menu_id'),

    );



and in Rolesmenus Model relations:


return array(

        'menu' => array(self::BELONGS_TO, 'Menu', 'menu_id'),

    );



So, I cant access $data->roles->can_view variable, when I var_dump all $data object I can see these atributes in _atributtes private array but I cant them access through CGridView.

Any ideas??

Try with a php expression:




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

'id'=>'menu-grid',

'selectableRows' => 2,

'dataProvider'=>$dataProvider,

'columns'=>array(

        'id',

        'title',

         array(

            'class'    => 'SCheckboxColumn',

            'header'   => 'View',

            'name'     => 'Roles[Actions][can_view]',

            'id'       => 'roles_action_can_view',

             'value'    => '$data->id',

            'checkBoxHtmlOptions' =>

                array('checked' => '$data->roles->can_view',), // <<-- Here!!!

        ),

    ),

));



Well, the problem was in sql. I solved problem in sql and write this model without yii relations, because in this case I must write:




SELECT t.* FROM ( SELECT * FROM table2 ) t2 LEFT JOIN table1 ON ...



Anyway, thanks for replay ;)