[SOLVED] CGridView with search and relations

Just can’t seem to work it out, Data from the relation doesn’t return.




        $model  = new Model('search');

        $search = $model->together()->with('related')->search();


        $this->widget('CGridView', array(

            'dataProvider'          => $search,

            'filter'                => $model

        ....

        ....

            array(

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

            ),



It works with lazy loading but I need eager.

Shouldn’t it be?





            array(

                'value'             => '$data->related->relatedAttr',

            ),



But that uses lazy loading (unless I’m mistaken).

forgot to mention relation,




    'related'  => array(

        self::BELONGS_TO,

        'RelatedModel',

        'key'

    )



I dont understand the use of with here:




$search = $model->together()->with('related')->search();

I think if should be in your search method:


public function search(){

  $criteria = new CDbC...

  $criteira->compare...

  $criteria->with = array('related');//Here

  return CAcviteDataProvider...

}

Yep that was it, Knew I was overlooking something.

Looking at it now I can see the search method doesn’t use the model instance for creating the provider.

thanks.

Nope, the Dataprodiver just requires the name of the model :)

Good to know its now working, please mark this topic as resolved, thanks! :D