CGridview default filter on related table

Hi guys

I have a gridview which filters and sorts perfectly with related columns included. Now I’d like to filter the data by default, but allow the user to view the data by turning the filter on. If I add the default filter in the search method in the model, the data is filtered, but the filters of course don’t allow the user to view what has been filtered out by default.

If I put the default filter in the action as follows:

public function actionList()


        $model = new Test('search');

        // This is the related field I wish to have a default value on

        $model->relation->field = 'defaultValue';

        $model->unsetAttributes();  // clear any default values

        if (isset($_GET['Test']))

            $model->attributes = $_GET['Test'];

        $this->render('list', array(

            'model' => $model,



I get the following error with this:

PHP Notice: Indirect modification of overloaded property Test::$relation has no effect 

I can get default filters to work from the action when there are no relations involve but does anyone have any idea of how to do with related tables? I’d rather avoid extensions if possible as I’m leaving this project shortly.


You do not want to use extensions, yet my RelatedSearchBehavior extension does the job.